Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.11.16;
Скачать: CL | DM;

Вниз

Выяснить наличие св-в Caption и Text   Найти похожие ветки 

 
123-ий ©   (2008-10-08 11:58) [0]

Перебираю компоненты формы таким способом:

 for i := 0 to ComponentCount - 1 do
   Components[i].блаблабла

Так вот можно ли выяснить, есть ли у данного компонента свойство Caption или Text?
Надо для того, чтобы сделать локализацию. Файлик с нужными строками грузится в память, и надо чтобы для всех контролов выставились Caption"ы и Text"ы из этого файлика. То есть ситуация такая, что есть строки (причем в начале каждой строки содержится параметр, указывающий куда эту строку "затолкнуть", то есть строка выглядит так: <Control>.<Property> = "блаблабла"), есть нужные компоненты, надо это всё как то совместить.


 
Palladin ©   (2008-10-08 12:00) [1]

http://www.delphimaster.ru/cgi-bin/forum.pl?n=18&search=%F1%E2%EE%E9%F1%F2%E2%EE+Caption


 
Rouse_ ©   (2008-10-08 12:23) [2]

unit Unit1;

interface

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

type
 TForm1 = class(TForm)
   Label1: TLabel;
   Memo1: TMemo;
   Edit1: TEdit;
   Button1: TButton;
   CheckBox1: TCheckBox;
   ListBox1: TListBox;
   ComboBox1: TComboBox;
   ScrollBar1: TScrollBar;
   Panel1: TPanel;
   procedure Button1Click(Sender: TObject);
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

uses
 TypInfo;

type
 TTextProperty = (tpCaption, tpText);
 TTextPropertyes = set of TTextProperty;

function QueryTextProperty(AObject: TObject): TTextPropertyes;
var
 I: Integer;
 FList: PPropList;
 FCount, FSize: Integer;
begin
 Result := [];
 if AObject = nil then Exit;
 if AObject.ClassInfo <> nil then
 begin
   FCount := GetPropList(AObject.ClassInfo, tkProperties, nil);
   FSize := FCount * SizeOf(Pointer);
   GetMem(FList, FSize);
   try
     GetPropList(AObject.ClassInfo, tkProperties, FList);
     if FCount > 0 then
       for I := 0 to FCount - 1 do
         case FList^[I].PropType^.Kind of
           tkString, tkLString, tkWString:
             if FList^[I].Name = "Caption" then
               Include(Result, tpCaption)
             else
               if FList^[I].Name = "Text" then
                 Include(Result, tpText);
         end;
   finally
     FreeMem(FList);
   end;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 I: Integer;
 TextPropertyes: TTextPropertyes;
 OutputString, CommaString: String;
begin
 Memo1.Lines.Clear;
 for I := 0 to ComponentCount  - 1 do
 begin
   TextPropertyes := QueryTextProperty(Components[I]);
   if TextPropertyes <> [] then
   begin
     OutputString := Components[I].Name;
     CommaString := "";
     if tpCaption in TextPropertyes then
     begin
       OutputString := OutputString + " has Caption";
       CommaString := ", ";
     end;
     if tpText in TextPropertyes then
       OutputString := OutputString + CommaString + " has Text";
     Memo1.Lines.Add(OutputString);
   end;
 end;
end;

end.


 
{RASkov} ©   (2008-10-08 12:36) [3]

Может пригодится в решении задачи:
type
 TForm1 = class(TForm)
   Button1: TButton;
   Panel1: TPanel;
   CheckBox1: TCheckBox;
   Label1: TLabel;
   RadioButton1: TRadioButton;
   RadioGroup1: TRadioGroup;
   GroupBox1: TGroupBox;
   Edit1: TEdit;
   MaskEdit1: TMaskEdit;
   SpeedButton1: TSpeedButton;
   BitBtn1: TBitBtn;
   LabeledEdit1: TLabeledEdit;
   procedure Button1Click(Sender: TObject);
 private { Private declarations }
 public  { Public declarations }
 end;

var Form1: TForm1;

implementation
{$R *.dfm}
type TCtrl = class(TControl);
procedure TForm1.Button1Click(Sender: TObject);
var N: Integer;
begin
 for N:=0 to ComponentCount-1 do
  if Components[N] is TControl then TCtrl(Components[N]).Text:="This "+Components[N].Name;
end;

end.


 
123-ий ©   (2008-10-08 13:26) [4]

ух ты. спасибо, помогли :)



Страницы: 1 вся ветка

Текущий архив: 2008.11.16;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.016 c
8-1187769846
ZMRaven
2007-08-22 12:04
2008.11.16
Поганое изображение.


2-1223103815
Smel
2008-10-04 11:03
2008.11.16
beginthread


2-1223547592
ВиталийАк
2008-10-09 14:19
2008.11.16
Canvas.DrawFocusRect


15-1221736846
Vlad Oshin
2008-09-18 15:20
2008.11.16
не знает ли кто ссылку на PL/SQL Developer, приемы работы?


6-1195035982
sdaf
2007-11-14 13:26
2008.11.16
чат для локальной сети