Autor Beitrag
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Fr 16.07.04 22:59 
hi,

ist es möglich alle in einem programm befindlichen "komponenten" - die eine caption property haben - (per schleife) abzufragen...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
TForm1 = class(TForm)
    panel1: TPanel;
    StatusBar1: TStatusBar;
    IdHTTP1: TIdHTTP;
    Image1: TImage;
    Label1: TLabel;


würde mir dann panel1 und label1 liefern

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Mo 19.07.2004 um 13:34

_________________
hans bist du das ?
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 18.07.04 16:30 
TForm stellt das Propterty Components zur Verfügung, das ist syntaktisch ein Array da sind alle Komponenten auf der Form drin.
Rauszufinden, ob die Komponente ein Caption-Property hat, ist da schon schwieriger. Wenn es dir nur um ganz bestimmte Komponenten geht, kannst du mit "is" prüfen, ob die Klasse stimmt. Ansonsten gibt es meines Wissens keien zuverlässige Methode, rauszufinden ob die Komponente eine Caption hat, denn die wird zwar in TControl eingeführt, aber nicht alle Nachkommen dieser Klasse müssen dieses Property ja auch veröffentlichen (z.B. TEdit).

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: So 18.07.04 16:53 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
{...}
uses {...}, TypInfo;
{...}
  if GetPropInfo(Edit1, 'Caption') = nil then
    ShowMessage('edit1.caption gibs net');
  if GetPropInfo(Label1, 'Caption') = nil then
    ShowMessage('label1.caption gibs net');
{...}


raziel

_________________
JSXGraph
Matthias-K
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271

Win95, Win98, Win2000, WinXP, Linux
D2, D4 Client/Server, D5 Enterprise, D6 Enterprise, D7 Enterprise, Delphi2005, C/C++ 3.0, C/C ++ 5.0, C/C++ 6.0
BeitragVerfasst: So 18.07.04 17:14 
hab grad mal bissle probiert, aber man bekommt nicht wirklich raus, ob die komponente eine caption eigenschaft hat.

hab es mal so probiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure tform1.button1click(sender : tobject);
var a : integer;
    f : tcomponent;
    t : string;
begin
  for a := 0 to components.componentscount do
    begin
      t := form1.Components[a].Name;
      f := components[a].FindComponent(t);
      //nur hier ist schluss
    end;
end;

nur, da man nicht an den typ der compo rankommt, hat man keine chance, per findcomponent auf die caption eigenschaft zuzugreifen.

müsste ich mal kucken, ob ich was genaues dazu finde!

mfg matthias

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: So 18.07.04 17:37 
*seufz* Es gibt doch sooo ein schönes und nützliches Delphi-Tag... naja. Zum Beispiel so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  p: PTypeInfo;
begin
  for i := 0 to ComponentCount-1 do
  begin
    p := Components[i].ClassInfo;
    if (GetPropInfo(p, 'Caption') <> nilthen
      SetPropValue(Label1, 'Caption''Hello, World!');
  end;
end;


TypInfo einbinden nicht vergessen!

raziel

//edit: überflüssiges entfernt... ;-)

_________________
JSXGraph
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 18.07.04 19:35 
raziel hat folgendes geschrieben:
//edit: überflüssiges entfernt... ;-)

Un dabei einen Fehlr in Zeile 10 übersehen: Muss heißen

ausblenden Delphi-Quelltext
1:
    SetPropValue(Components[i], 'Caption''Hello, World!');					


Sonst wird immer wieder das Label1 editiert ;-)

Ansonsten ist der Source genial!

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