Registriert seit: 19. Jul 2005
43 Beiträge
|
Re: Enthält Array1 das Array2?
25. Feb 2007, 18:59
Delphi-Quellcode:
var
Grosses: array[0..5] of char = ('A', 'B', 'C', 'D', 'E', 'F');
Kleines1: array[0..2] of char = ('C', 'D', 'E');
Kleines2: array[0..2] of char = ('C', 'D', 'F');
Kleines3: array[0..2] of char = ('E', 'F', 'G');
function KinG(K, G: array of char): boolean;
begin
result := pos(K, G) > 0;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
if KinG(Kleines2, Grosses) then showmessage('Gross enthält Klein1')
else showmessage('nicht gefunden');
end;
//--------------------- Allgemein --------------------
type
art = Integer; // für diesen Fall
var
Grss: array[0..5] of art = (1, 13, 33, 125, 2, 77);
Kl1: array[0..2] of art = (33, 125, 2);
Kl2: array[0..2] of art = (33, 125, 77);
Kl3: array[0..2] of art = (2, 77, 444);
function KinGx(K, G: array of art): boolean;
var
se, sg, sk: integer;
A, P: PChar;
begin
sg := sizeof(G);
sk := sizeof(K);
se := sizeof(G[0]);
P := @G;
A := P;
repeat
result := comparemem(@K, P, sk);
if result then break;
inc(P, se);
until P - A > sg - sk;
end;
procedure TForm2.Button4Click(Sender: TObject);
begin
if KinGx(Kl2, Grss) then showmessage('Gross enthält Klein1')
else showmessage('nicht gefunden');
end;
|
|
Zitat
|