![]() |
TTreeView und Formularnamen als String
Hallo,
ich habe ein Projekt übernommen und benötige etwas Hilfe. Zunächst einmal möchte ich den Text eines angeklickten Eintrags in einem TTreeView ermitteln. Meine Versuche dazu sind alle gescheitert. In der Datenbank existiert eine Tabelle, in der aufgezeichnet ist, was beim Klick auf eines der TreeView-Items passieren soll. Nun soll der TreeView variabel werden und die Konstruktion reicht nicht mehr aus. Meine Idee ist, in der Tabelle den Namen der FORM als String einzutragen und diese Form dann aufzurufen. Ich scheitere aber daran, den String(z.B. "KundenForm") so umzuwandeln, dass ich sagen könnte: KUNDENFORM.SHOW... Kann mir jemand helfen? Viele Grüße Heiko |
AW: TTreeView und Formularnamen als String
Du weißt also, wie das Formular heißt, dann kannst Du es über den Namen suchen:
Mal als Idee hingedaddelt:
Delphi-Quellcode:
procedure ShowForm(NameDesFormulars : String);
var f : TWinControl; begin f := FindControl(NameDesFormulars); if Assigned(f) then if f is TForm then TForm(f).Show; end; ... qry.sql.Text := 'select Formularname from Tabelle where Spalte = ' + WertAusDemTreeView; qry.Open; ShowForm(qry.FieldByName('Formularname').AsString; qry.Close; ... |
AW: TTreeView und Formularnamen als String
Ähm...
Delphi-Quellcode:
Zielführender wäre hier vielleicht
{ Find a TWinControl given a window handle }
{ The global atom table is trashed when the user logs off. The extra test below protects UI interactive services after the user logs off. Added additional tests to enure that Handle is at least within the same process since otherwise a bogus result can occur due to problems with GlobalFindAtom in Winapi.Windows. } function FindControl(Handle: HWnd): TWinControl;
Delphi-Quellcode:
function FindGlobalComponent(const Name: string): TComponent;
|
AW: TTreeView und Formularnamen als String
Ups, da hab' ich schon wieder meinen typischen / tückischen Schreib(Verwechslungs)fehler von FindControl und FindComponent gemacht :oops::cry:
Delphi-Quellcode:
Und ja, je nach Delphiversion gibt es weitere / andere Suchmöglichkeiten, um über den Namen an Komponenten ... zu kommen.
procedure ShowForm(NameDesFormulars : String);
var f : TComponent; begin f := FindComponent(NameDesFormulars); // oder f := FindGlobalComponent(NameDesFormulars); if Assigned(f) then if f is TForm then TForm(f).Show; end; ... qry.sql.Text := 'select Formularname from Tabelle where Spalte = ' + WertAusDemTreeView; qry.Open; ShowForm(qry.FieldByName('Formularname').AsString; qry.Close; ... Weitere Versuche von Ansätzen:
Delphi-Quellcode:
procedure ShowFormByName(FormName : String);
var i : Integer; begin for i := 0 to Self.ControlCount - 1 do begin if Self.Controls[i] is TForm then begin if Self.Controls[i].Name = FormName then begin TForm(Self.Controls[i]).Show; end; end; end; // oder for i := 0 to Application.ComponentCount - 1 do begin if Application.Components[i].Name = FormName then begin if Application.Components[i] is TForm then begin TForm(Application.Components[i]).Show; end; end; end; // oder for i := 0 to Screen.FormCount - 1 do begin if Screen.Forms[i].Name = FormName then begin if Screen.Forms[i] is TForm then begin TForm(Screen.Forms[i]).Show; end; end; end; end; |
AW: TTreeView und Formularnamen als String
[del]
|
AW: TTreeView und Formularnamen als String
Die globale Funktion FindControl(Handle) hilft eh nicht, denn wer findet erstmal das Handle? (oder willst'e ALLE Fenster im System durchgehn :?:)
Und ansonsten gibt es FindControl(Name) aber das ist, wie FindComponent(Name), eine Methode und keine globale Funktion. ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:35 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 by Thomas Breitkreuz