diff --git a/ide/projecticon.pas b/ide/projecticon.pas index 36b7048bf8..07aa36fa89 100644 --- a/ide/projecticon.pas +++ b/ide/projecticon.pas @@ -59,7 +59,8 @@ type function GetStream: TStream; procedure SetStream(AStream: TStream); - function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override; + function UpdateResources(AResources: TAbstractProjectResources; + const MainFilename: string): Boolean; override; function CreateIconFile: Boolean; property IconData: TIconData read FData write SetIconData; @@ -76,7 +77,7 @@ const function TProjectIcon.GetStream: TStream; begin - if FData <> nil then + if length(FData)>0 then begin Result := TMemoryStream.Create; Result.WriteBuffer(FData[0], Length(FData)); @@ -206,8 +207,9 @@ procedure TProjectIcon.SetIconData(const AValue: TIconData); begin if (Length(AValue) = Length(FData)) and (FData <> nil) and - (CompareByte(AValue[0], FData[0], Length(FData)) = 0) then - Exit; + (CompareByte(AValue[0], FData[0], Length(FData)) = 0) + then + Exit; FData := AValue; Modified := True; end; diff --git a/ide/projectresources.pas b/ide/projectresources.pas index e5cd9413c6..2a7de5f3ea 100644 --- a/ide/projectresources.pas +++ b/ide/projectresources.pas @@ -203,9 +203,12 @@ var OutStream: TStringStream; begin OutStream := TStringStream.Create(''); - BinaryToLazarusResourceCode(AResource, OutStream, ResourceName, ResourceType); - FLazarusResources.Add(OutStream.DataString); - OutStream.Free; + try + BinaryToLazarusResourceCode(AResource, OutStream, ResourceName, ResourceType); + FLazarusResources.Add(OutStream.DataString); + finally + OutStream.Free; + end; end; procedure TProjectResources.Clear; diff --git a/ideintf/projectresourcesintf.pas b/ideintf/projectresourcesintf.pas index 6d939c16a8..33e739039d 100644 --- a/ideintf/projectresourcesintf.pas +++ b/ideintf/projectresourcesintf.pas @@ -46,7 +46,8 @@ type destructor Destroy; override; procedure AddSystemResource(const AResource: String); virtual; abstract; - procedure AddLazarusResource(AResource: TStream; const ResourceName, ResourceType: String); virtual; abstract; + procedure AddLazarusResource(AResource: TStream; + const ResourceName, ResourceType: String); virtual; abstract; property Messages: TStringList read FMessages; end; diff --git a/lcl/lresources.pp b/lcl/lresources.pp index 89c0089494..83fb5aeb34 100644 --- a/lcl/lresources.pp +++ b/lcl/lresources.pp @@ -1140,64 +1140,68 @@ begin RangeString:=false; CurLine:=1; RightMargin:=80; - while ReadChar(c) do begin - NewRangeString:=(ord(c)>=32) and (ord(c)<=127); - // check if new char fits into line or if a new line must be started - if NewRangeString then begin - if RangeString then - MinCharCount:=2 // char plus ' - else - MinCharCount:=3; // ' plus char plus ' - if c='''' then inc(MinCharCount); - end else begin - MinCharCount:=1+length(ByteToStr[c]); // # plus number - if RangeString then - inc(MinCharCount); // plus ' for ending last string constant - end; - if x+MinCharCount>RightMargin then begin - // break line - if RangeString then begin - // end string constant - WriteChar(''''); + if ReadBufLen>0 then begin + while ReadChar(c) do begin + NewRangeString:=(ord(c)>=32) and (ord(c)<=127); + // check if new char fits into line or if a new line must be started + if NewRangeString then begin + if RangeString then + MinCharCount:=2 // char plus ' + else + MinCharCount:=3; // ' plus char plus ' + if c='''' then inc(MinCharCount); + end else begin + MinCharCount:=1+length(ByteToStr[c]); // # plus number + if RangeString then + inc(MinCharCount); // plus ' for ending last string constant end; - // write line ending - WriteShortString(LineEnd); - x:=0; - inc(CurLine); - // write indention - WriteString(Indent); - inc(x,length(Indent)); - // write operator - if (CurLine and 63)<>1 then - WriteChar('+') - else - WriteChar(','); - inc(x); - RangeString:=false; - end; - // write converted byte - if RangeString<>NewRangeString then begin - WriteChar(''''); - inc(x); - end; - if NewRangeString then begin - WriteChar(c); - inc(x); - if c='''' then begin - WriteChar(c); + if x+MinCharCount>RightMargin then begin + // break line + if RangeString then begin + // end string constant + WriteChar(''''); + end; + // write line ending + WriteShortString(LineEnd); + x:=0; + inc(CurLine); + // write indention + WriteString(Indent); + inc(x,length(Indent)); + // write operator + if (CurLine and 63)<>1 then + WriteChar('+') + else + WriteChar(','); + inc(x); + RangeString:=false; + end; + // write converted byte + if RangeString<>NewRangeString then begin + WriteChar(''''); inc(x); end; - end else begin - WriteChar('#'); - inc(x); - WriteShortString(ByteToStr[c]); - inc(x,length(ByteToStr[c])); + if NewRangeString then begin + WriteChar(c); + inc(x); + if c='''' then begin + WriteChar(c); + inc(x); + end; + end else begin + WriteChar('#'); + inc(x); + WriteShortString(ByteToStr[c]); + inc(x,length(ByteToStr[c])); + end; + // next + RangeString:=NewRangeString; end; - // next - RangeString:=NewRangeString; - end; - if RangeString then begin - WriteChar(''''); + if RangeString then begin + WriteChar(''''); + end; + end else begin + WriteShortString(''''''); end; Indent:=copy(Indent,3,length(Indent)-2); s:=LineEnd+Indent+']);'+LineEnd;