![]() |
Eigene klasse mit FindComponent
Hallo,
ich stehe wieder vor einem Problem. Ich habe eine eigene Klasse geschrieben, die mir auf eine x-beliebige Form Controls wie ein StringGrid usw anzeigt. Jetzt will ich bei einem StringGrid auf eine einzelne Zelle mit einer InputBox werte eintragen. Funktioniert alles einwandfrei, bis zu dem punkt, wo die Daten an das StringGrid übergeben werden. Ich vermute, daß es mit FindComponent zusammenhängt. Die StringGrids sind dyn. erzeugt worden. Ich hoffe, daß ich mein Problem genau beschrieben habe, und hoffe, daß ihr mir helfen könnt. Danke im vorraus Christian |
Re: Eigene klasse mit FindComponent
etwas quelltext wäre sinnvoll. Wie erzeugst du das Stringgrid dynamisch und wie greifst du mit FindComponent darauf zu?
|
Re: Eigene klasse mit FindComponent
zeig mal den Kot mit dem du einfügst.
und was genau geht nicht? lässt sich nicht compillieren? kommt ne AV? |
Re: Eigene klasse mit FindComponent
Wie erzeugst du diese? Mit Owner?
Zitat:
|
Re: Eigene klasse mit FindComponent
Delphi-Quellcode:
und damit... type TTurnierGruppen = class(TObject) private fGruppen, fSpieler : integer; fForm : TForm; fParent : TWinControl; fLeft, fTop : integer; aStringGrid : array of TAdvStringGrid; aTab : TTabSheet; aPageControl : TPageControl; aGruppenErgebnis : array of TAdvStringGrid; ... SetLength(aStringGrid, fGruppen); SetLength(aGruppenErgebnis, fGruppen); aPageControl := TPageControl.Create(nil); with aPageControl do begin Parent := fParent; Left := fLeft; Top := fTop; Width := 580; Height := 200; for i := 1 to fGruppen do begin aTab := TTabSheet.Create(nil); aTab.PageControl := aPageControl; aTab.Name := 'tab_Gruppe' + IntToStr(i); aTab.Caption := 'Gruppe ' + IntToStr(i); aStringGrid[j] := TAdvStringGrid.Create(nil); with aStringGrid[j] do begin Parent := aTab; Name := 'grd_Gruppe' + IntToStr(i); Left := 10; Top := 10; DefaultRowHeight := 20; DefaultColWidth := 60; Width := DefaultColWidth * 6; Height := 150; ColCount := fSpieler + 1; RowCount := fSpieler + 1; for k := 0 to fSpieler do Colors[k, k] := clBtnFace; OnClickCell := aGruppenClickCell; for m := 1 to ColCount - 1 do Cells[m, 0] := 'test' + IntToStr(m); for m := 1 to RowCount - 1 do Cells[0, m] := 'test' + IntToStr(m); end; aGruppenErgebnis[l] := TAdvStringGrid.Create(nil); with aGruppenErgebnis[l] do begin Parent := aTab ; Name := 'grd_GruppeErgebnis' + IntToStr(i); Left := aStringGrid[j].Width + 20; Top := 10; Width := 190; Height := 150; RowCount := fSpieler + 1; FixedRows := 1; ColCount := 5; ColWidths[0] := 60; ColWidths[1] := 30; ColWidths[2] := 30; ColWidths[3] := 30; ColWidths[4] := 30; DefaultRowHeight := 20; MergeCells(1, 0, 2, 1); MergeCells(3, 0, 2, 1); Cells[1,0] := 'Punkte'; Cells[3,0] := 'Legs'; for o := 1 to ColCount - 1 do for p := 1 to RowCount - 1 do cells[o, p] := '0'; end; end; end; ...
Delphi-Quellcode:
Ich hoffe, daß der Code soweit stimmt. Das generieren der Komponenten funktioniert einwandfrei, bis ich was eintragen will.
TAdvStringGrid(fForm.FindComponent('grd_GruppeErgebnis' + IntToStr(aPageControl.ActivePageIndex))).Cells[3, aCol] := IntToStr(veLegs); <-- hier springt er in den Quellcode rein.
|
Re: Eigene klasse mit FindComponent
du hast keinen Owner angegeben bei
Delphi-Quellcode:
FindComponent macht nichts anderes als in der Liste des Owners zu suchen. Wenn kein Owner angegeben ist kann auch nirgends gesucht werden. Gib als Owner das Form an dann findet deine Componente auch das PageControl (vorrausgesetzt deine Componente hat den gleichen Owner)
TPageControl.Create(nil);
|
Re: Eigene klasse mit FindComponent
Delphi-Quellcode:
.FindComponent der Form kann das Grid nur finden, wenn sie dieses auch kennt. Also:
aPageControl := TPageControl.Create(nil);
Delphi-Quellcode:
aPageControl := TPageControl.Create(Form1);
|
Re: Eigene klasse mit FindComponent
Hallo,
so funktioniert es auch nicht.
Delphi-Quellcode:
Nur wenn ich die Zeile so ändere.
ShowMessage( TAdvStringGrid(fForm.FindComponent('grd_GruppeErgebnis' + IntToStr(aPageControl.ActivePageIndex))).GetVersionString);
Delphi-Quellcode:
Woran könnte das liegen??
ShowMessage( TAdvStringGrid(fForm.FindComponent('grd_GruppeErgebnis1')).GetVersionString);
Vielen Dank für eure Hilfe. Gruß Christian |
Re: Eigene klasse mit FindComponent
ich würde sagen das es daran liegt das aPageControl.ActivePageIndex nicht 1 ist. Du solltest generell den Rückgabewert von FindComponente erstmal auswerten um zu wissen ob die Componente gefunden wurde und nur im Erfolgsfall casten und darauf zugreifen.
Und als kleiner Hinweis: "funktioniert nicht" ist keine Fehlermeldung. Je genauer die Fehlerbeschreibung ist destso schneller und besser kann dir geholfen werden. Denn "funktioniert nicht" kann eine Fehlermeldung sein, aber es kann auch einfach sein das etwas anderes passiert als erwartet etc. |
Re: Eigene klasse mit FindComponent
suuuuuuuuuuuuuuper.
Dank Dir SirThornberry. Es lag an der for schleife. ActivePageIndex kann ja nicht 0 sein, da die Schleife bei 1 angefangen hatte. :oops:
Delphi-Quellcode:
for i := 1 to fGruppen - 1 do
begin Vielen Dank, ihr seid ein super Team |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz