Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Find Component (https://www.delphipraxis.net/3708-find-component.html)

Hellcat 26. Mär 2003 15:25


Find Component
 
Zu welcher Unit gehört eigentlich FindComponent? Ich hab bei meiner eigenen Unit folgende uses-Zeile:
Delphi-Quellcode:
uses SysUtils, ExtCtrls, StdCtrls, Controls, Classes, Graphics, Dialogs;
und erhalte beim Befehl 'FindComponent' immer die Meldung 'undeclared identifier';

jbg 26. Mär 2003 15:27

FindComponent ist keine Funktion oder Prozedur, sondern eine Method von TComponent. Diese wiederum befindet sich in Classes.pas.

Hellcat 26. Mär 2003 15:35

Aber warum spuckt er mir dann bei obriger Deklaration diese Meldung aus - denn Classes hab ich ja aufgeführt....

sakura 26. Mär 2003 15:57

An welcher Stelle benutzt Du die Methode denn. Wahrscheinlich in einer Prozedur/Funktion ausserhalb einer Klasse, bzw. in einer Methode einer Klasse, welche nicht von TComponent abgeleitet wurde.

...:cat:...

Hellcat 26. Mär 2003 16:12

Ich poste hier mal die Unit:
Delphi-Quellcode:
unit UnitFunc;

interface

uses SysUtils, ExtCtrls, StdCtrls, Controls, Classes, Graphics, Dialogs; {Standard-Units auf die zurückgegriffen wird}

    procedure Farbewechseln (Sender: TPanel; Button: TMousebutton);
    function Zeitangabe:string;
    function THL (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    function Sound (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    function Schloss (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    procedure speichern;

implementation

procedure speichern;
var save: Textfile;
    Hname, Zeit, HFarbe, kette: string;
    Schl, THL, Sound:boolean;
    i: integer;
begin
  kette := '';
  for i := 1 to 35 do
  begin
    kette := kette + ((FindComponent('PanLab' + IntToStr(i)) as TLabel) .Caption,
                  (FindComponent('PanLabT' + Inttostr(i)) as TLabel).caption,
                  IntToHex(((FindComponent('PanHalle' + InttoStr(i))as TPanel).Color),6),
                  BoolToStr(bildTHL[i]), BoolToStr(bildSchl[i]),BoolToStr(bildSound[i]));
  end;
end;

jbg 26. Mär 2003 17:48

FindComponent ist eine Methode von TComponent. Du kannst sie nur innerhalb einer Klasse bzw. Mit "IrgendeinObjekt.FindComponent" aufrufen.

Da ich annehme das die gesuchte Komponente auf dem Hauptformular liegt, kannst du mit Application.MainForm.FindComponent auf dieses zugreifen.

mirage228 26. Mär 2003 17:49

du kannst auch der speichern prozedur als parameter das formular angeben! (alternative)

Delphi-Quellcode:
unit UnitFunc;

interface

uses SysUtils, ExtCtrls, StdCtrls, Controls, Classes, Graphics, Dialogs; {Standard-Units auf die zurückgegriffen wird}

    procedure Farbewechseln (Sender: TPanel; Button: TMousebutton);
    function Zeitangabe:string;
    function THL (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    function Sound (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    function Schloss (Sender: TImage; Button: TMousebutton; Bild: boolean): boolean;
    procedure speichern(formular: TForm);

implementation
procedure speichern(formular: Tform);
var save: Textfile;
    Hname, Zeit, HFarbe, kette: string;
    Schl, THL, Sound:boolean;
    i: integer;
begin
  kette := '';
  for i := 1 to 35 do
  begin
    kette := kette + ((Formular.FindComponent('PanLab' + IntToStr(i)) as TLabel) .Caption,
                  (Formular.FindComponent('PanLabT' + Inttostr(i)) as TLabel).caption,
                  IntToHex(((Formular.FindComponent('PanHalle' + InttoStr(i))as TPanel).Color),6),
                  BoolToStr(bildTHL[i]), BoolToStr(bildSchl[i]),BoolToStr(bildSound[i]));
  end;
end;
natürlich gehts auch mit Application.MainForm.FindComponent


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:57 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz