Autor Beitrag
Chalybis
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 30.11.04 21:27 
Hallo ihr

Ich habe ne blöde Frage und ehrlich gesagt auch keine Ahnung ob ich hier richtig bin ich hoffe es einfach mal.
Und Zwar ist meine Frage wie ich zum beispiel Variablen Name oder ein Komponenten Name aus verschiedenen variable und oder werte zusammen setzen kann.

Ich will zumbeispiel, dass in einer einer schleife erst das edit Feld x1 ausgelesen wird dann das Feld x2 und so weiter.

Ich hoffe ihr versteht mein Problem ;)

vielen dank Chalybis

Als beispiel eine schleife mit dem Problem:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=1 to 15 do begin
'edit'i.text:=i*5;
{hier weiß ich nicht wie ich das 'edit'i schreiben soll}
end;


Moderiert von user profile iconChristian S.: Meta- durch Delphi-Tags ersetzt
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 30.11.04 21:31 
Wie wär's mit FindComponent? Einfach mal in der OH gucken.

String zusammensetzen:
ausblenden Delphi-Quelltext
1:
MyString := MyString + MyOtherString;					
Chalybis Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 30.11.04 21:38 
Sry ich habe es mir jetzt gerade mal in der Hilfe angeguckt und es danach versucht und es hat nicht geklappt ich hänge einfach mal mein QUelltext an

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
    procedure Tform1.probieren(s1,s2,s3,s4:integer {;var dis:double});
   var xn,yn,xz,yz,ent,dis:double;
    begin
      xn:=Strtofloat((findcomponent('x'+inttostr(s1)).text);
      yn:=Strtofloat((findcomponent('y'+inttostr(s1)).text);
      xz:=Strtofloat((findcomponent('x'+inttostr(s2)).text);
      yz:=Strtofloat((findcomponent('y'+inttostr(s2)).text);
{hier kommt jetzt der Rest. Die einzelnen edit Felder heißen x1,y1,x2,y2 und so weiter}
end;
herzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 168

WINXP pro, SUSE Linux 9.0
D7 Pers.
BeitragVerfasst: Di 30.11.04 21:49 
Einfach nur was getestet... sieht nicht toll aus aber erfüllt den Zweck...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  i:integer;
  x:TComponent;
begin
  for i:=1 to 5 do begin
    x:=FindComponent('edit'+InTToStr(i));
    if x<>nil then
    if x.ClassType=TEdit then
      showmessage('Found');
  end;
end;
Chalybis Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 30.11.04 21:55 
Sry, aber bei mir will das noch nich nächstes Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var test:string;
begin  
test:='x'+Inttostr(1);
 edit1.text:=test.text;
end;


Fehler:Record, Objekt oder Klassentyp erforderlich.

Könnt ihr mir das mal an diesem Beispiel erklären ;)

danke Chalybis
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 30.11.04 22:09 
Moin!

Hm, ist zwar eher Klasse "Workaround" als "Lösung", aber sollte trotzdem funktionieren:

Wie wäre es denn, wenn du dir die Komponenten in ein Array packst, auf das du dann indiziert zugreifst? Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  Editfeld = ARRAY [1..3] of TEdit;
  i: Integer;

for i := 1 to 3 do
  Editfeld[i].Text := 'Feld '+IntToStr(i);


cu
Narses
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 30.11.04 22:24 
Das gibt ne Fette AccessViolation, weil du die Komponenten in dem Array nicht vorinitialisierst. Du musst wirklich mit FindComponent diese erst suchen!

_________________
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.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 30.11.04 22:36 
Titel: Statischer Ansatz...
Moin!

Zitat:
Das gibt ne Fette AccessViolation

Klar, war ja auch nur als Code-Schnipsel hingeschmiert (OK, ich hab´s nicht dazugeschrieben...).

Hier also der komplette Code, wenn man einen statischen Ansatz wählt und nicht mitdenken will :roll: :
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    Editfeld: ARRAY[1..3] of TEdit;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Editfeld[1] := Edit1;
  Editfeld[2] := Edit2;
  Editfeld[3] := Edit3;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var
    i: Integer;
begin
  for i := 1 to 3 do
    Editfeld[i].Text := 'Feld '+IntToStr(i);
end;

end.


Kann man natürlich auch dynamisch aufziehen, aber das ist mir gerade zu viel Arbeit, das auszutesten.

cu
Narses
CodeRed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.12.04 17:40 
hi!
ich hätte dazu auch noch eine frage, die im prinzip sehr ähnlich ist:

ich hab 3 tabsheets und auf jedem befindet sich eine radiogroup.
die radiogroup auf der ersten setite heißt radiogroup0, auf der zweiten seite radiogroup1 (also wie der index der tabsheet auch).

kann ich hier auch irgendwie sagen, dass er je nachdem welches tabsheet aktiv ist die entsprechende radiogroup nehmen soll?


edit:
ich hab's gelöst. hier die lösung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
  private
    { Private-Deklarationen }
    RadioGroup : Array[0..1] of TRadioGroup;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
  i := PageControl1.TabIndex;
  RadioGroup[i].itemindex := StrToInt(edit1.Text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RadioGroup[0] := Radiogroup0;
  RadioGroup[1] := Radiogroup1;
end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
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: So 05.12.04 20:33 
Den aktuell aktiven Tabsheet erhälst du über PageControl.ActivePageIndex. Danach baust du aus diesem einfach den Namen der RadioGroup zusammen und übergibst diesen Wert an FindComponent. Danach teilst du über einen Typecast dem Compiler nur noch mit, dass das Ergebnis eine TRadioGroup ist. Der Zugriff erfolgt dann ganz normal.

_________________
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.