unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl;type TForm1 = class(TForm) FileListBox1: TFileListBox; Button1: TButton; OpenDialog1: TOpenDialog; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private FDfmFile:TStringList; procedure AnalyseDFM(DFM_File:string); function GetGBStr(Source:string):string; { Private declarations } public constructor Create(AOwner:tcomponent);override; destructor Destroy;override; { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure StrtoStrlist(Sign: string; Str: string; var Strlist: TStringList); var temp: string; begin Strlist.Text:=''; while pos(Sign, str)> 0 do begin temp:= copy(Str,1, pos(Sign, Str)-1); Delete(str, 1, pos(Sign, str)+length(Sign)-1); Strlist.Add(temp); end; if Length(Str)> 0 then Strlist.Add(Str); end;procedure TForm1.AnalyseDFM(DFM_File:string); var i:Integer; str:string; begin FDfmFile.Clear; FDfmFile.LoadFromFile(DFM_File); for i:=FDfmFile.Count -1 downto 0 do begin str :=FDfmFile.Strings[i]; if pos('ClientHeight',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ClientWidth',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ItemIndex',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ExplicitWidth',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ExplicitHeight',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('DisableStringTrim',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ExplicitTop',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('ExplicitLeft',str)>0 then begin FDfmFile.Delete(i); continue; end; if pos('#',str)>0 then FDfmFile.Strings[i]:=GetGBStr(FDfmFile.Strings[i]); end; FDfmFile.SaveToFile(DFM_File); end;procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin FileListBox1.Directory:=ExtractFileDir(OpenDialog1.FileName); end; end;procedure TForm1.Button2Click(Sender: TObject); var i:Integer; FileName:string; begin for i:=0 to FileListBox1.Items.Count -1 do begin FileName:=FileListBox1.Items.Strings[i]; if ExtractFileExt(FileName)='.dfm' then AnalyseDFM(FileName); end; end;constructor TForm1.Create(AOwner: tcomponent); begin inherited; FDfmFile:=TStringList.Create; end;destructor TForm1.Destroy; begin FDfmFile.Free; inherited; end;function TForm1.GetGBStr(Source: string): string; var i,index:Integer; str,temp,temp1,num,beginother,endother:WideString; strlist:tstringlist; procedure Parser(str:string;var ANum:WideString;var Abeginother:WideString;var Aendother:WideString); var len:Integer; chr:Char; isbegin,ATag:Boolean; begin isbegin :=true; ATag:=False; for len:=1 to Length(str) do begin chr:=str[len]; if (not ATag) and ((chr='0') or (chr='1') or (chr='2') or (chr='1') or (chr='3') or (chr='4') or (chr='5') or (chr='6') or (chr='7') or (chr='8') or (chr='9')) then begin isbegin:=false; ANum :=ANum +chr; end else begin if chr='''' then ATag:=not ATag else begin if isbegin then Abeginother:=Abeginother+chr else Aendother :=Aendother +chr; end; end; end; end; begin str:=Source; index :=pos('=',str); temp:=copy(str,1,index+1); strlist :=TStringList.Create; try StrtoStrlist('#',copy(str,index+2,length(str)-index),strlist); temp1:=strlist.Text; strlist.Delete(0); str:=''; for i:=0 to strlist.Count -1 do begin num:=''; beginother:=''; endother:=''; Parser(strlist.Strings[i],num,beginother,endother); if length(num)>0 then begin temp1:=WideChar(StrToInt(num)); str :=str+beginother+temp1+endother; end else str :=str+beginother+endother; end; Result:=temp+''''+str+''''; finally strlist.Free; end; end;end.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl;type
TForm1 = class(TForm)
FileListBox1: TFileListBox;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
FDfmFile:TStringList;
procedure AnalyseDFM(DFM_File:string);
function GetGBStr(Source:string):string;
{ Private declarations }
public
constructor Create(AOwner:tcomponent);override;
destructor Destroy;override;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure StrtoStrlist(Sign: string; Str: string; var Strlist: TStringList);
var
temp: string;
begin
Strlist.Text:='';
while pos(Sign, str)> 0 do
begin
temp:= copy(Str,1, pos(Sign, Str)-1);
Delete(str, 1, pos(Sign, str)+length(Sign)-1);
Strlist.Add(temp);
end;
if Length(Str)> 0 then
Strlist.Add(Str);
end;procedure TForm1.AnalyseDFM(DFM_File:string);
var
i:Integer;
str:string;
begin
FDfmFile.Clear;
FDfmFile.LoadFromFile(DFM_File); for i:=FDfmFile.Count -1 downto 0 do
begin
str :=FDfmFile.Strings[i];
if pos('ClientHeight',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ClientWidth',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ItemIndex',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ExplicitWidth',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ExplicitHeight',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('DisableStringTrim',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ExplicitTop',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('ExplicitLeft',str)>0 then
begin
FDfmFile.Delete(i);
continue;
end;
if pos('#',str)>0 then
FDfmFile.Strings[i]:=GetGBStr(FDfmFile.Strings[i]);
end; FDfmFile.SaveToFile(DFM_File);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
FileListBox1.Directory:=ExtractFileDir(OpenDialog1.FileName);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
FileName:string;
begin
for i:=0 to FileListBox1.Items.Count -1 do
begin
FileName:=FileListBox1.Items.Strings[i];
if ExtractFileExt(FileName)='.dfm' then
AnalyseDFM(FileName);
end;
end;constructor TForm1.Create(AOwner: tcomponent);
begin
inherited;
FDfmFile:=TStringList.Create;
end;destructor TForm1.Destroy;
begin
FDfmFile.Free;
inherited;
end;function TForm1.GetGBStr(Source: string): string;
var
i,index:Integer;
str,temp,temp1,num,beginother,endother:WideString;
strlist:tstringlist; procedure Parser(str:string;var ANum:WideString;var Abeginother:WideString;var Aendother:WideString);
var
len:Integer;
chr:Char;
isbegin,ATag:Boolean;
begin
isbegin :=true;
ATag:=False;
for len:=1 to Length(str) do
begin
chr:=str[len];
if (not ATag) and ((chr='0') or (chr='1') or (chr='2') or (chr='1') or (chr='3')
or (chr='4') or (chr='5') or (chr='6') or (chr='7') or (chr='8') or (chr='9')) then
begin
isbegin:=false;
ANum :=ANum +chr;
end
else
begin
if chr='''' then
ATag:=not ATag
else
begin
if isbegin then
Abeginother:=Abeginother+chr
else
Aendother :=Aendother +chr;
end;
end;
end;
end;
begin
str:=Source;
index :=pos('=',str);
temp:=copy(str,1,index+1); strlist :=TStringList.Create;
try
StrtoStrlist('#',copy(str,index+2,length(str)-index),strlist);
temp1:=strlist.Text;
strlist.Delete(0);
str:='';
for i:=0 to strlist.Count -1 do
begin
num:='';
beginother:='';
endother:='';
Parser(strlist.Strings[i],num,beginother,endother);
if length(num)>0 then
begin
temp1:=WideChar(StrToInt(num));
str :=str+beginother+temp1+endother;
end
else
str :=str+beginother+endother;
end;
Result:=temp+''''+str+'''';
finally
strlist.Free;
end;
end;end.
不久前我也有这个需求,这个是我做的一个转换工具的源码,可以参考一下