LCL: fixed writing empty resource

git-svn-id: trunk@17887 -
This commit is contained in:
mattias 2008-12-22 22:12:34 +00:00
parent f4560dae0c
commit 2e9143f08c
4 changed files with 72 additions and 62 deletions

View File

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

View File

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

View File

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

View File

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