(*//
标题:处理窗体代码文本
说明:将窗体代码VCL6处理成VCL5格式
设计:Zswang
日期:2002-07-20
支持:wjhu111@21cn.com
//*)
///////Begin Source
function ProcessFormSource(mSource, mDest: TStrings): Boolean;
var
I, J, K: Integer;
S: string;
vTempStr, vLeftStr: string;
vWideByte: Integer;
begin
Result := False;
if not (Assigned(mSource) and Assigned(mDest)) then Exit;
mDest.Clear;
for I := 0 to mSource.Count - 1 do begin
S := mSource[I];
if Pos('#', S) > 0 then begin
vTempStr := '';
vLeftStr := '';
K := 0;
for J := 1 to Length(S) do
case K of
0: begin //空区
case S[J] of
'''': begin
K := 1;
vLeftStr := vLeftStr + S[J];
end;
'#': K := 2;
else vLeftStr := vLeftStr + S[J];
end;
end;
1: begin //''''区
if S[J] = '''' then K := 0;
vLeftStr := vLeftStr + S[J];
end;
2: begin //#区
if S[J] in ['0'..'9', '$', 'a'..'f', 'A'..'F'] then
vTempStr := vTempStr + S[J]
else begin
K := Pos(S[J], '''#');
vWideByte := StrToIntDef(vTempStr, 0);
if vWideByte <= 256 then begin
vLeftStr := vLeftStr + '#' + vTempStr;
if S[J] = '''' then vLeftStr := vLeftStr + S[J];
end else begin
if Copy(vLeftStr, Length(vLeftStr), 1) = '''' then
Insert(WideChar(vWideByte), vLeftStr, Length(vLeftStr))
else vLeftStr := vLeftStr + QuotedStr(WideChar(vWideByte));
if S[J] = '''' then Delete(vLeftStr, Length(vLeftStr), 1);
end;
vTempStr := '';
end;
end;
end;
if K = 2 then begin
vWideByte := StrToIntDef(vTempStr, 0);
if vWideByte <= 256 then
vLeftStr := vLeftStr + '#' + vTempStr
else begin
if Copy(vLeftStr, Length(vLeftStr), 1) = '''' then
Insert(WideChar(vWideByte), vLeftStr, Length(vLeftStr))
else vLeftStr := vLeftStr + QuotedStr(WideChar(vWideByte));
end;
end;
S := vLeftStr;
end;
mDest.Add(S);
end;
Result := True;
end; { ProcessFormSource }
///////End Source
///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
ProcessFormSource(Memo1.Lines, Memo2.Lines);
end;
///////End Demo