Autor Beitrag
ImPact
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win XP
D3
BeitragVerfasst: Di 19.07.05 16:02 
Moin Moin!

ich würd gerne vom ding her eine variable/eigenschaft mit mehreren vergleichen.
Als Beispiel:

ausblenden Delphi-Quelltext
1:
if (StringGrid1.cells[0,0]=Edit1.text) or ((StringGrid1.cells[0,0]=Edit2.text) and ((StringGrid1.cells[0,0]=Edit1.text)) or ...usw...then					


also ... geht das auch kürzer und eleganter, ohne das ich jetzt das StringGrid.cells[0,0] immer wieder schrieben muss ?
habs auf ein paar varianten probiert, aber der Compiler meckert immer "operator nich anwendbar"... :cry:

ThX schonma :)
---------------------
GreeTz
Impact

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 19.07.05 16:05 
N'Abend...
Pack deine Vergleichstrings in eine TStringlist und überprüfe mit IndexOf, ob der zu suchende String in der Liste ist.

_________________
We are, we were and will not be.
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Di 19.07.05 16:08 
ausblenden Delphi-Quelltext
1:
2:
t = StringGrid1.cells[0,0];
if (t=Edit1.text) or ((t=Edit2.text) and ((t=Edit1.text)) or ...usw...then


macht die Sache doch schon kürzer

//Edit: Die StringList-Idee ist auch gut

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.
ImPact Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win XP
D3
BeitragVerfasst: Di 19.07.05 16:17 
erstma danke für die schnelle antwort!

ich bin auch davon überzeugt, dass mir dass helfen würde, nur hab ich keinen blassen schimmer :lol:

kannste mir vielleicht nen kleinen fetzten code geben, damit ich weiß wie das so aussieht? die delphihilfe is für mich ma wieder unbrauchbar -g-

thx
-------------
Impact
Lemmingman2005
Hält's aus hier
Beiträge: 12

Windows XP, Gentoo Linux 2005.0
Delphi 7.0 Enterprise
BeitragVerfasst: Di 19.07.05 16:43 
Stringlist erstellen (mit TStringlist.Create)
Einträge mit Add einfügen
Einträge über Index (siehe Arrays) abfragen

That's all
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 19.07.05 19:28 
Mit etwas Source sieht's so aus:

ausblenden Statische Suche nach bestimmten Strings
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Function IsStringListed(AStr:String): Boolean;
Var SL: TStringList;
begin
    SL := TStringList.Create;
    try
        SL.Text := 'String 1'#13#10'String 2'#13#10'Was anderes'#13#10'Noch was'#13#10'...';
        Result := SL.IndexOf(AStr) <> -1;
    finally
        FreeAndNil(SL);
    end;
end;


Mit dynamik sähe das ganze dann z.B. so aus:

ausblenden Dynamische Suche nach bestimmten Strings
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Function IsStringListed(AStr, AList:String): Boolean;
Var SL: TStringList;
begin
    SL := TStringList.Create;
    try
        SL.Text := AList;
        Result := SL.IndexOf(AStr) <> -1;
    finally
        FreeAndNil(SL);
    end;
end;


@Source 1: Die markierte Stelle ist die eigentliche Abfrage. Das andere ist nur Vorgeplänkel ...

@Source 2: Die dynamische Zuweisung. Format für AList ist genauso, wie in der ersten Variante.

//Edit: Syntaxfehler in Delphi-Blöcken korrigiert.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.


Zuletzt bearbeitet von BenBE am Mi 20.07.05 15:25, insgesamt 1-mal bearbeitet
ImPact Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win XP
D3
BeitragVerfasst: Mi 20.07.05 14:59 
nagut... ich machs wie Tilman vorgeschlagen hat.

Der StringListkram is mir (noch) zu hoch, und ich möchte nich einfach Code kopieren den ich selber nich verstehe...

------------------
THX
Impact