From 7382c718081f3244689ce00b9f5fdcf97ba098b9 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 5 Nov 2005 13:34:53 +0000 Subject: [PATCH] clean up git-svn-id: trunk@8067 - --- ide/lazdocfrm.pas | 25 ++++++++++++---- ide/main.pp | 75 ++++++++++++++++++++++++++--------------------- lcl/lresources.pp | 38 ++++++++++++++++++++++-- 3 files changed, 97 insertions(+), 41 deletions(-) diff --git a/ide/lazdocfrm.pas b/ide/lazdocfrm.pas index d13b1f5465..d0af5cf2d0 100644 --- a/ide/lazdocfrm.pas +++ b/ide/lazdocfrm.pas @@ -650,12 +650,27 @@ begin BrowseExampleButton.Enabled := EnabledState; end; -function ToUnixLineEnding(s: String): String; +function ToUnixLineEnding(const s: String): String; +var + p: Integer; begin - if LineEnding = #10 then - Result := s - else - Result := StringReplace(s, LineEnding, #10, [rfReplaceAll]); + Result:=s; + p:=1; + while (p<=length(s)) do begin + if not (s[p] in [#10,#13]) then begin + inc(p); + end else begin + // line ending + if (ps[p+1]) then begin + // double character line ending + Result:=copy(Result,1,p-1)+#10+copy(Result,p+2,length(Result)); + end else if s[p]=#13 then begin + // single char line ending #13 + Result[p]:=#10; + end; + inc(p); + end; + end; end; procedure TLazDocForm.Save; diff --git a/ide/main.pp b/ide/main.pp index 4fd0dfe89c..fcc248c4a9 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -4404,6 +4404,45 @@ begin //debugln('TMainIDE.DoLoadLFM LFM="',LFMBuf.Source,'"'); ComponentLoadingOk:=true; + + // find the classname of the LFM, and check for inherited form + ReadLFMHeader(LFMBuf.Source,NewClassName,LFMType); + InheritedForm:=CompareText(LFMType,'inherited')=0; + if NewClassName='' then begin + Result:=MessageDlg(lisLFMFileCorrupt, + Format(lisUnableToFindAValidClassnameIn, ['"', LFMBuf.Filename, '"']), + mtError,[mbIgnore,mbCancel,mbAbort],0); + exit; + end; + + // find the ancestor type in the source + NewAncestorName:=''; + AncestorType:=TForm; + if not CodeToolBoss.FindFormAncestor(AnUnitInfo.Source,NewClassName, + NewAncestorName,true) + then begin + DebugLn('TMainIDE.DoLoadLFM Filename="',AnUnitInfo.Filename,'" NewClassName=',NewClassName,'. Unable to find ancestor class: ',CodeToolBoss.ErrorMessage); + end; + AncestorType:=nil; + if NewAncestorName<>'' then begin + if CompareText(NewAncestorName,'TDataModule')=0 then begin + // use our TDataModule + // (some fpc versions have non designable TDataModule) + AncestorType:=TDataModule; + end else begin + APersistentClass:=Classes.GetClass(NewAncestorName); + if (APersistentClass<>nil) + and (APersistentClass.InheritsFrom(TComponent)) then begin + // ancestor type is a registered component class + AncestorType:=TComponentClass(APersistentClass); + end; + end; + end; + if AncestorType=nil then + AncestorType:=TForm; + DebugLn('TMainIDE.DoLoadLFM AncestorClassName=',NewAncestorName,' AncestorType=',AncestorType.ClassName); + + // BinLFMStream:=TExtMemoryStream.Create; try @@ -4413,40 +4452,6 @@ begin AnUnitInfo.ComponentLastLFMStreamSize:=TxtLFMStream.Size; TxtLFMStream.Position:=0; - // find the classname of the LFM, and check for inherited form - ReadLFMHeader(TxtLFMStream,NewClassName,LFMType); - InheritedForm:=CompareText(LFMType,'inherited')=0; - if NewClassName='' then begin - Result:=MessageDlg(lisLFMFileCorrupt, - Format(lisUnableToFindAValidClassnameIn, ['"', LFMBuf.Filename, '"']), - mtError,[mbIgnore,mbCancel,mbAbort],0); - exit; - end; - - // find the ancestor type in the source - NewAncestorName:=''; - AncestorType:=TForm; - if not CodeToolBoss.FindFormAncestor(AnUnitInfo.Source,NewClassName, - NewAncestorName,true) - then begin - DebugLn('TMainIDE.DoLoadLFM Filename="',AnUnitInfo.Filename,'" NewClassName=',NewClassName,'. Unable to find ancestor class: ',CodeToolBoss.ErrorMessage); - end; - if NewAncestorName<>'' then begin - if CompareText(NewAncestorName,'TDataModule')=0 then begin - // use our TDataModule - // (some fpc versions have non designable TDataModule) - AncestorType:=TDataModule; - end else begin - APersistentClass:=Classes.GetClass(NewAncestorName); - if (APersistentClass<>nil) - and (APersistentClass.InheritsFrom(TComponent)) then begin - // ancestor type is a registered component class - AncestorType:=TComponentClass(APersistentClass); - end; - end; - end; - DebugLn('TMainIDE.DoLoadLFM AncestorClassName=',NewAncestorName,' AncestorType=',AncestorType.ClassName); - // convert text to binary format try if AnUnitInfo.ComponentLastBinStreamSize>0 then @@ -4474,6 +4479,8 @@ begin if not (ofProjectLoading in Flags) then FormEditor1.ClearSelection; if InheritedForm then begin + // TODO WORKAROUND: inherited does not yet work completely, + // so help programmer by opening the lfm file Result:=DoOpenEditorFile(LFMBuf.Filename,AnUnitInfo.EditorIndex+1, Flags+[ofOnlyIfExists,ofQuiet,ofRegularFile]); Exit; diff --git a/lcl/lresources.pp b/lcl/lresources.pp index 7cf476bfe5..7e900b7f84 100644 --- a/lcl/lresources.pp +++ b/lcl/lresources.pp @@ -229,6 +229,8 @@ function LFMtoLRSstream(LFMStream, LRSStream: TStream): boolean;// true on succe function FindLFMClassName(LFMStream: TStream):AnsiString; procedure ReadLFMHeader(LFMStream: TStream; out LFMClassName: String; out LFMType: String); +procedure ReadLFMHeader(LFMSource: string; out LFMClassName: String; + out LFMType: String); function CreateLFMFile(AComponent: TComponent; LFMStream: TStream): integer; type @@ -1121,8 +1123,8 @@ begin object Form1: TForm1 inherited AboutBox2: TAboutBox2 - -> LFMClassName is the last word of the first line - => LFMType is the first word on the line + - LFMClassName is the last word of the first line + - LFMType is the first word on the line } LFMClassName := ''; LFMType := ''; @@ -1144,6 +1146,38 @@ begin LFMStream.Position:=0; end; +procedure ReadLFMHeader(LFMSource: string; out LFMClassName: String; + out LFMType: String); +var + p: Integer; + LineEndPos: LongInt; +begin + { examples: + object Form1: TForm1 + inherited AboutBox2: TAboutBox2 + + - LFMClassName is the last word of the first line + - LFMType is the first word on the line + } + LFMClassName := ''; + + // read first word => LFMType + p:=1; + while (p<=length(LFMSource)) + and (LFMSource[p] in ['a'..'z','A'..'Z','0'..'9','_']) do + inc(p); + LFMType:=copy(LFMSource,1,p); + + // find end of line + while (p<=length(LFMSource)) and (not (LFMSource[p] in [#10,#13])) do inc(p); + LineEndPos:=p; + // read last word => LFMClassName + while (p>1) + and (LFMSource[p-1] in ['a'..'z','A'..'Z','0'..'9','_']) do + dec(p); + LFMClassName:=copy(LFMSource,p,LineEndPos-p); +end; + function CreateLFMFile(AComponent: TComponent; LFMStream: TStream): integer; // 0 = ok // -1 = error while streaming AForm to binary stream