(Gast)
n/a Beiträge
|
AW: funktion erstellen... weiß nicht weiter
17. Aug 2011, 12:13
hier das endprodukt... danke nochmal ihr seid die besten
Delphi-Quellcode:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function Sort(ASrcA, ASrcD: String): Integer;
function CharToInt(AValue: String): Integer;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
CharTable: array[0..51] of String =
(' A', ' a', ' B', ' b', ' C', ' c', ' D', ' d', ' E', ' e', ' F', ' f', ' G', ' g', ' H',
' h',' I', ' i', ' J', ' j', ' K', ' k', ' L', ' l', ' M', ' m', ' N', ' n', ' O', ' o',
' P', ' p', ' Q', ' q', ' R', ' r', ' S', ' s', ' T', ' t', ' U', ' u', ' V', ' v',
' W', ' w', ' X', ' x', ' Y', ' y', ' Z', ' z');
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i, j : Integer; //Position
Buffer: String;
begin
for j:=0 to Memo1.Lines.count -2 do
begin
for i:=j +1 to Memo1.Lines.Count -1 do
begin
if Sort(Memo1.Lines[j], Memo1.Lines[i]) > 0 then
begin
Buffer:= Memo1.Lines[j];
Memo1.Lines[j]:= Memo1.Lines[i];
Memo1.Lines[i]:= Buffer;
end;
end;
end;
end;
function TForm1.CharToInt(AValue: String): Integer;
var
i: Integer;
begin
Result := -1;
for i := 1 to Length(CharTable) do
begin
if AValue = Chartable[i] then
begin
Result := i;
Break;
end;
end;
end;
function TForm1.Sort(ASrcA, ASrcD: String): Integer;
var
i, j: Integer;
lResult: Integer;
begin
Result := 0;
for i:=1 to Length(ASrcD) do
begin
if CharToInt(ASrcA[i]) = CharToInt(ASrcD[i]) then
begin
Result := 0;
end else
begin
if CharToInt(ASrcA[i]) < CharToInt(ASrcD[i]) then
begin
Result:= -1;
Break;
end else
begin
Result := +1;
Break;
end;
end;
end;
end;
end.
|