Registriert seit: 21. Mai 2004
809 Beiträge
Delphi 7 Personal
|
Re: probleme mit der ausgabe von strings
10. Apr 2005, 19:49
Ich würde es mit zwei Stringlisten machen:
Delphi-Quellcode:
type
TMorse = class(TForm)
code: TMemo;
decode: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
SearchList,
ReplaceList: TStrings;
procedure AddMorse(const ASearch, AReplace: String);
public
{ Public-Deklarationen }
end;
var
Morse: TMorse;
implementation
{$R *.dfm}
procedure TMorse.AddMorse(const ASearch, AReplace: String);
begin
SearchList.Add(ASearch);
ReplaceList.Add(AReplace);
end;
procedure TMorse.FormCreate(Sender: TObject);
begin
SearchList := TStringList.Create;
ReplaceList := TStringList.Create;
AddMorse('a', '.- ');
AddMorse('b', '-... ');
AddMorse('c', '-.-. ');
//...
end;
procedure TMorse.FormDestroy(Sender: TObject);
begin
SearchList.Free;
ReplaceList.Free;
end;
procedure TMorse.Button1Click(Sender: TObject);
var
fLine,
fDecode: String;
x, y,
fIndex: Integer;
begin
fDecode := '';
for y := 0 to code.Lines.Count - 1 do
begin
fLine := code.Lines[y];
for x := 1 to Length(fLine) do
begin
fIndex := SearchList.IndexOf(fLine[x]);
if fIndex = -1 then
fDecode := fDecode + fLine[x]
else
fDecode := fDecode + ReplaceList[fIndex];
end;
end;
decode.Text := fDecode;
end;
MfG Pr0g
|
|
Zitat
|