@
41linea41 haklı ve hakikaten statik ve doğru yöntem belirttiği şekildedir.
@
tmrksmt'un bahsettiği veya bahsedeceği metod sanırım aşağıda belirteceğim olacaktı.
* Bir diğer yandan Türkçe dil dosyasını İngilizce'ye kendiniz çevirirsiniz bu sorun olmaz, ancak üçüncü başka diller için liste halinde başkalarına yollayıp "siz bunun çevirisini yapın" diyebilmek için alternatif bir yöntem gerektiğini değerlendirdim ve aşağıdaki procedure çıktı.
* Bu sadece size asistanlık yapmak için döküm yapıyor, istediğinizi direkt değil. Çünkü öncelikle formdaki butonlarınıza karşılık birer alias (rumuz) oluşturmak ya da buton / nesne isimlerini rumuza olacak şekilde değiştirmek gerekebilir. Listeye bakarak butonları BT_01, BT_01, Label'ları LB_01, LB_02, ComboBox'ları CB_01 vb. sıralı bir şekilde ikililer halinde yeniden isimlendirmek isteyebilirsiniz.
* Özetle uzun uzadıya ekran tasarımı, bileşen ekle / kaldır vs. karmaşık bir yazılım hazırlık sürecinden sonra öngörülemeyen şekilde bana böyle bu tip bir talep gelseydi, yerinde olsam ne yapardım diye düşününce :
Procedure'e parametre olarak vereceğin TFORM'un üzerinde ne kadar bileşen varsa döngü ile tek tek dolaşan, dolaşırken de
Caption/Text/Lines.Text/Items.Text içeriğini almak için alternatifleri ortak paydaya alan bir çözüm.
Hedef / Amaç : Bu ne işe yarayacak. Tüm bileşenlerin isimlerini bu dökümden yola çıkarak bir referans dil INI paketi oluşturacak, sonra bunun tersi işlem ile bu içeriği proje OnShow olayında tüm nesnelere geri basmak. INI dosyasını direkt de oluşturabilirdik ama bu sadece çıkış noktası olarak değerlendirmeye değer mi karar sizin.
procedure FormObjects( aForm : TForm; aList: TStrings );
Type tComp = Record
aProp,
aName,
aValue : String;
end;
Type tCompList = Record
aType : String;
aComp : Array of tComp;
end;
var
i, j, k : Integer;
LTypeIdx : Integer;
LCompIdx : Integer;
LArray : Array of tCompList;
LClass : String;
LComp : tComp;
LTypeList : TStringList;
LPropInfo : System.TypInfo.PPropInfo;
begin
LTypeList := TStringList.Create;
try
for i := 0 to aForm.ComponentCount-1 do
begin
LComp := default( tComp );
LPropInfo := GetPropInfo( aForm.Components[i], 'Caption' );
if LPropInfo <> nil then begin
LComp.aProp := 'Caption';
LComp.aValue := GetStrProp( aForm.Components[i], 'Caption' );
end;
LPropInfo := GetPropInfo( aForm.Components[i], 'Text' );
if LPropInfo <> nil then begin
LComp.aProp := 'Text';
LComp.aValue := GetStrProp( aForm.Components[i], 'Text' );
end;
LPropInfo := GetPropInfo( aForm.Components[i], 'Items' );
if LPropInfo <> nil
then begin
if GetObjectProp( aForm.Components[i], 'Items' ) is TStrings then
begin
With TStrings( GetObjectProp( aForm.Components[i], 'Items' ) ) do
begin
Delimiter := '|';
StrictDelimiter := True;
if LPropInfo <> nil then begin
LComp.aProp := 'Items';
LComp.aValue := DelimitedText;
end;
end;
end;
end;
LPropInfo := GetPropInfo( aForm.Components[i], 'Lines' );
if LPropInfo <> nil
then begin
if GetObjectProp( aForm.Components[i], 'Lines' ) is TStrings then
begin
With TStrings( GetObjectProp( aForm.Components[i], 'Lines' ) ) do
begin
Delimiter := '|';
StrictDelimiter := True;
if LPropInfo <> nil then begin
LComp.aProp := 'Lines';
LComp.aValue := DelimitedText;
end;
end;
end;
end;
// Collect to Array
if LComp.aProp <> '' then
begin
LComp.aName := aForm.Components[i].Name;
LClass := aForm.Components[i].ClassName;
LTypeIdx := LTypeList.IndexOf( LClass );
if ( LTypeIdx < 0 )then
begin // new type
LTypeList.Add( LClass );
LTypeIdx := LTypeList.IndexOf( LClass );
SetLength( LArray, Length(LArray) + 1 );
LArray[LTypeIdx].aType := LClass;
SetLength( LArray[LTypeIdx].aComp, 1 );
end
else
if ( LComp.aProp <> '' ) then begin
SetLength( LArray[LTypeIdx].aComp, Length( LArray[LTypeIdx].aComp )+1 );
end;
LCompIdx := High( LArray[LTypeIdx].aComp );
LArray[LTypeIdx].aComp[ LCompIdx ] := LComp;
end;
end;
finally
LTypeList.Free;
end;
// Çıktısını Listeye alalım...
for i := 0 to High(LArray) do
begin
aList.Add( StringOfChar('-', 80) );
for j := 0 to High(LArray[i].aComp) do
begin
aList.Add( Format('%s : (%s) : %s = "%s"', [ LArray[i].aType
,LArray[i].aComp[j].aProp
,LArray[i].aComp[j].aName
,LArray[i].aComp[j].aValue
] ) );
end;
end;
SetLength(LArray, 0);
Finalize(LArray);
end;
Kullanımı :
procedure TForm1.Button1Click(Sender: TObject);
var
LList : TStringList;
begin
LList := TStringList.Create;
try
FormObjects( self, LList );
Memo1.Lines.Text := LList.text;
finally
LList.Free;
end;
end;
Çıktı kümesi de şu şekilde. ( klasördeki rastgele örnek bir proje google calendar uygulama taslağı )
--------------------------------------------------------------------------------
TPanel : (Caption) : Panel7 = "Panel7"
TPanel : (Caption) : Panel6 = ""
TPanel : (Caption) : Panel4 = ""
TPanel : (Caption) : Panel5 = ""
TPanel : (Caption) : Panel1 = ""
TPanel : (Caption) : Panel3 = ""
--------------------------------------------------------------------------------
TLabel : (Caption) : Label28 = "Takvim Olay Listesi"
TLabel : (Caption) : Label20 = "Tarih Aralığı"
TLabel : (Caption) : Label13 = "Olay Kaydı"
TLabel : (Caption) : Label14 = "Başlama Tarih / Saat"
TLabel : (Caption) : Label15 = "Bitiş Tarih / Saat"
TLabel : (Caption) : Label21 = "Başlık"
TLabel : (Caption) : Label22 = "Konum"
TLabel : (Caption) : Label23 = "Bilgi Notu"
TLabel : (Caption) : Label25 = "Color Id"
TLabel : (Caption) : Label16 = "Katılımcılar"
TLabel : (Caption) : Label17 = "eposta"
TLabel : (Caption) : Label18 = "Ad/Soyad"
TLabel : (Caption) : Label19 = "Bilgi Notu"
TLabel : (Caption) : Label4 = "Google Calendar API"
TLabel : (Caption) : Label1 = "Calendar Id"
TLabel : (Caption) : Label2 = "00:57:55"
TLabel : (Caption) : Label7 = "LOG Verileri"
--------------------------------------------------------------------------------
TBitBtn : (Caption) : BitBtn5 = "Olay Listesi Getir"
TBitBtn : (Caption) : BitBtn3 = "Kişilere Ekle"
TBitBtn : (Caption) : BitBtn2 = "Takvim YENİ OLAY "
TBitBtn : (Caption) : BitBtn6 = "Kişileri Temizle"
TBitBtn : (Caption) : BitBtn7 = "Takvim Bilgilerini GÜNCELLE"
TBitBtn : (Caption) : BitBtn_OAuth = "OAuth 2.0"
--------------------------------------------------------------------------------
TCheckBox : (Caption) : CheckBox_SilinmisKayitlar = "Silinimiş Kayıtlar Dahil"
TCheckBox : (Caption) : CheckBox2 = "Tüm Gün"
TCheckBox : (Caption) : CheckBox3 = "Organizasyondan"
--------------------------------------------------------------------------------
TEdit : (Text) : Edit16 = ""
TEdit : (Text) : Edit17 = ""
TEdit : (Text) : Edit10 = ""
TEdit : (Text) : Edit11 = ""
TEdit : (Text) : Edit12 = ""
TEdit : (Text) : Edit2 = ""
--------------------------------------------------------------------------------
TMemo : (Lines) : Memo2 = ""
TMemo : (Lines) : Memo1 = ""
--------------------------------------------------------------------------------
TComboBox : (Items) : ComboBox1 = "a|b|c|d|e|f|g"
--------------------------------------------------------------------------------
TButton : (Caption) : Button1 = "Button1"
--------------------------------------------------------------------------------
TMenuItem : (Caption) : miSeciliKisiSil = "Seçili Kişiyi Sil"
TMenuItem : (Caption) : miOlaySil = "Seçili Olayı Sil"
