如果是大型程序就使用Delphi自带的,如果是小程序,不妨将文字写在INI文件中,然后读入程序即可……举例: unit global;interfaceuses Forms,IniFiles,SysUtils,StdCtrls,Menus,ExtCtrls;function PutAllComponentsToFile(orgForm:TForm;FileName:String):Boolean;implementationfunction PutAllComponentsToFile(orgForm:TForm;FileName:String):Boolean; var i,j:Integer; OrgIniFile:TIniFile; begin Result := False;
OrgIniFile := TIniFile.Create(ExtractFilePath(ParamStr(0))+FileName+'.Ini'); try for i := 0 to orgForm.ComponentCount-1 do begin //Standard if orgForm.Components[i] is TLabel then begin OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TLabel).Name+'.Caption',(orgForm.Components[i] as TLabel).Caption); OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TLabel).Name+'.Hint',(orgForm.Components[i] as TLabel).Hint); end; if orgForm.Components[i] is TComboBox then begin OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.Hint',(orgForm.Components[i] as TComboBox).Hint); OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.Text',(orgForm.Components[i] as TComboBox).Text); OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.ItemCount',IntToStr((orgForm.Components[i] as TComboBox).Items.Count)); for j := 0 to (orgForm.Components[i] as TComboBox).Items.Count-1 do begin OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.ItemText'+IntToStr(j),(orgForm.Components[i] as TComboBox).Items.Strings[j]); end; end; //...... end; finally OrgIniFile.Free; ReSult := True; end;
如果是大型程序就使用Delphi自带的,如果是小程序,不妨将文字写在INI文件中,然后读入程序即可……举例:
unit global;interfaceuses Forms,IniFiles,SysUtils,StdCtrls,Menus,ExtCtrls;function PutAllComponentsToFile(orgForm:TForm;FileName:String):Boolean;implementationfunction PutAllComponentsToFile(orgForm:TForm;FileName:String):Boolean;
var
i,j:Integer;
OrgIniFile:TIniFile;
begin
Result := False;
OrgIniFile := TIniFile.Create(ExtractFilePath(ParamStr(0))+FileName+'.Ini');
try
for i := 0 to orgForm.ComponentCount-1 do begin
//Standard
if orgForm.Components[i] is TLabel then begin
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TLabel).Name+'.Caption',(orgForm.Components[i] as TLabel).Caption);
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TLabel).Name+'.Hint',(orgForm.Components[i] as TLabel).Hint);
end;
if orgForm.Components[i] is TComboBox then begin
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.Hint',(orgForm.Components[i] as TComboBox).Hint);
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.Text',(orgForm.Components[i] as TComboBox).Text);
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.ItemCount',IntToStr((orgForm.Components[i] as TComboBox).Items.Count));
for j := 0 to (orgForm.Components[i] as TComboBox).Items.Count-1 do begin
OrgIniFile.WriteString('LANGUAGE',(orgForm.Components[i] as TComboBox).Name+'.ItemText'+IntToStr(j),(orgForm.Components[i] as TComboBox).Items.Strings[j]);
end;
end;
//......
end;
finally
OrgIniFile.Free;
ReSult := True;
end;
end;end.