Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Pos and Copy (https://www.delphipraxis.net/135021-pos-copy.html)

safak67 3. Jun 2009 11:33


Pos and Copy
 
Hi, also meine frage.. im unten angegeben quelltext wird ja der String angezeig wenn ein + vorkommt, wie schreibe ich das programm um damit bei allen operatoren(+ - * /) die segmente initialisiert werden..?
Delphi-Quellcode:
procedure TFormTR.spErgebnisClick(Sender: TObject);
  var Formular,Seg1,Seg2: string;
begin
  Formular := LabelAnzeige.Caption;
  if pos('+',Formular) > 1 then
  begin
    Seg1 := copy(Formular,1,pos('+',Formular) - 1);
    Seg2 := copy(Formular,pos('+',Formular) + 1,length(Formular));
  end;
  ShowMessage(Seg1+'+'+Seg2);

end;

Luckie 3. Jun 2009 11:45

Re: Pos and Copy
 
Überleg mal welches ist denn die entscheidende Zeile in dem Quellcode ist.

Klaus01 3. Jun 2009 11:50

Re: Pos and Copy
 
Delphi-Quellcode:
procedure TFormTR.spErgebnisClick(Sender: TObject);
  var
    Formular,Seg1,Seg2: string;
    position : Byte;
    zeichen : char;
begin
  Formular := LabelAnzeige.Caption;
  zeichen := '+';
  position := pos(zeichen,Formular);
  if position > 1 then
    begin
      Seg1 := copy(Formular,1,position - 1);
      Seg2 := copy(Formular,position + 1,length(Formular));
    end
  else
    ShowMessage('Zeichen ('+zeichen+')nicht gefunden!););
end;
.. etwas umgestaltet

Auf anraten von Luckie noch etwas umgebaut.

Aber was soll mit Seg1 und Seg2 passieren, sie sind nur lokal definiert??

Grüße
Klaus

Luckie 3. Jun 2009 11:52

Re: Pos and Copy
 
Was zeigt die ShowMessage an, wenn das Zeichen nicht gefunden wurde?

safak67 3. Jun 2009 11:54

Re: Pos and Copy
 
ok ich habs gelöst danke trotzdem..
ich habe es mi einer schleife gemacht


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz