git-svn-id: trunk@8067 -
This commit is contained in:
mattias 2005-11-05 13:34:53 +00:00
parent 679cd0bc8e
commit 7382c71808
3 changed files with 97 additions and 41 deletions

View File

@ -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 (p<length(s)) and (s[p+1] in [#10,#13]) and (s[p]<>s[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;

View File

@ -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;

View File

@ -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