|
var i,iBegCount,iEndCount:Integer; ObjString,Line,ClassStr:String; begin iBegCount:=0; iEndCount:=0; ClassStr := Trim(UpperCase(TypeString)); for i:=BegLine to list.Count-1 do begin line := UpperCase(list[i]); if Pos('OBJECT',line)>0 then begin if (TypeString='') or (Pos(': '+ClassStr,line)>0) then Inc(iBegCount); end else if (iBegCount>iEndCount) and (trim(line)='END') then Inc(iEndCount);
if iBegCount>0 then Result := Result + list[i] + #13#10;
if (iBegCount>0) and (iBegCount=iEndCount) then ExIT; end; end;
procedure DeleteErrorLines(list:TStrings); var i:Integer; line:String; begin if list.Count=0 then ExIT;
i:=0; while i<list.Count do begin line := Trim(list[i]); if Copy(line,1,2)='On' then list.Delete(i) else Inc(i); end; end; procedure ReadForm(aFrom : TComponent;aFileName :string=''); var FrmStrings : TStrings; begin RegisterClass(TPersistentClass(aFrom.ClassType)); FrmStrings:=TStringlist.Create ; try if trim(aFileName)='' then FrmStrings.LoadFromFile( gsPathInfo+'\'+aFrom.Name+'.txt') else FrmStrings.LoadFromFile(aFileName); while aFrom.ComponentCount>0 do aFrom.Components[0].Destroy ; aFrom:=StringToComponent(FrmStrings.Text,aFrom) finally FrmStrings.Free; end; UnRegisterClass(TPersistentClass(aFrom.ClassType)); end; function LoadTextForm(FileName:String):TForm; var list:TStrings; FirstLine:String; iPos : Integer; Form : TForm; begin Result := nil;
if FileExists(FileName)=False then ExIT;
Form := TForm.Create(Application); list := TStringList.Create; try list.LoadFromFile(FileName); if list.Count=0 then ExIT;
FirstLine := list[0]; iPos := Pos(': ',FirstLine); if iPos = 0 then //找不到': ',格式不对 ExIT;
list[0]:=Copy(FirstLine,1,iPos)+' TForm';
DeleteErrorLines(list);
StringToComponent(list.Text,Form); Result := Form; except Form.Free; Result := nil; end; list.Free; end; function LoadTextForm2(FileName:String;out ErrMsg:string):TForm; var list:TStrings; FirstLine:String; iPos : Integer; Form : TForm; begin Result := nil;
if FileExists(FileName)=False then begin ErrMsg := '无效的文件名!'; ExIT; end;
Form := TForm.Create(Application); list := TStringList.Create; try list.LoadFromFile(FileName); if list.Count=0 then ExIT;
FirstLine := list[0]; iPos := Pos(': ',FirstLine); if iPos = 0 then //找不到': ',格式不对 begin ErrMsg := '找不到'': '',文件格式不对'; ExIT; end;
list[0]:=Copy(FirstLine,1,iPos)+' TForm';
DeleteErrorLines(list);
StringToComponent(list.Text,Form); Result := Form; except on e:exception do begin Form.Free; Result := nil; ErrMsg := '读入文件错误:'+e.Message; end; end; list.Free; end;
inITialization begin InITClassType(AllCmpClass); RegisterAllClasses(AllCmpClass); end;
finalization UnRegisterAllClasses(AllCmpClass);
end.
上一页 [1] [2] [3] |