MG: added TPicture clipboard support

git-svn-id: trunk@1507 -
This commit is contained in:
lazarus 2002-03-11 23:22:46 +00:00
parent e42cefbb37
commit da158e6e83
9 changed files with 232 additions and 86 deletions

View File

@ -124,7 +124,7 @@ type
xtExtended, xtCurrency, xtComp, xtInt64, xtCardinal, xtQWord, xtBoolean, xtExtended, xtCurrency, xtComp, xtInt64, xtCardinal, xtQWord, xtBoolean,
xtByteBool, xtLongBool, xtString, xtAnsiString, xtShortString, xtWideString, xtByteBool, xtLongBool, xtString, xtAnsiString, xtShortString, xtWideString,
xtPChar, xtPointer, xtConstOrdInteger, xtConstString, xtConstReal, xtPChar, xtPointer, xtConstOrdInteger, xtConstString, xtConstReal,
xtConstSet, xtConstBoolean, xtAddress, xtLongInt, xtNil); xtConstSet, xtConstBoolean, xtAddress, xtLongInt, xtWord, xtNil);
TExpressionTypeDescs = set of TExpressionTypeDesc; TExpressionTypeDescs = set of TExpressionTypeDesc;
const const
@ -133,12 +133,12 @@ const
'Extended', 'Currency', 'Comp', 'Int64', 'Cardinal', 'QWord', 'Boolean', 'Extended', 'Currency', 'Comp', 'Int64', 'Cardinal', 'QWord', 'Boolean',
'ByteBool', 'LongBool', 'String', 'AnsiString', 'ShortString', 'WideString', 'ByteBool', 'LongBool', 'String', 'AnsiString', 'ShortString', 'WideString',
'PChar', 'Pointer', 'ConstOrdInt', 'ConstString', 'ConstReal', 'ConstSet', 'PChar', 'Pointer', 'ConstOrdInt', 'ConstString', 'ConstReal', 'ConstSet',
'ConstBoolean', '@-Operator', 'LongInt', 'Nil' 'ConstBoolean', '@-Operator', 'LongInt', 'Word', 'Nil'
); );
xtAllTypes = [xtContext..High(TExpressionTypeDesc)]; xtAllTypes = [xtContext..High(TExpressionTypeDesc)];
xtAllPredefinedTypes = xtAllTypes-[xtContext]; xtAllPredefinedTypes = xtAllTypes-[xtContext];
xtAllIntegerTypes = [xtInt64, xtQWord, xtConstOrdInteger, xtLongInt]; xtAllIntegerTypes = [xtInt64, xtQWord, xtConstOrdInteger, xtLongInt, xtWord];
xtAllBooleanTypes = [xtBoolean, xtByteBool, xtLongBool]; xtAllBooleanTypes = [xtBoolean, xtByteBool, xtLongBool];
xtAllRealTypes = [xtReal, xtConstReal, xtSingle, xtDouble, xtExtended, xtAllRealTypes = [xtReal, xtConstReal, xtSingle, xtDouble, xtExtended,
xtCurrency, xtComp]; xtCurrency, xtComp];
@ -465,6 +465,10 @@ begin
Result:=xtCurrency Result:=xtCurrency
else if CompareIdentifiers(Identifier,'LONGINT'#0)=0 then else if CompareIdentifiers(Identifier,'LONGINT'#0)=0 then
Result:=xtLongInt Result:=xtLongInt
else if CompareIdentifiers(Identifier,'WORD'#0)=0 then
Result:=xtWord
else if CompareIdentifiers(Identifier,'LONGWORD'#0)=0 then
Result:=xtCardinal
else else
Result:=xtNone; Result:=xtNone;
end; end;

View File

@ -918,7 +918,9 @@ begin
Add('POINTER' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('POINTER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('INT64' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('INT64' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('CARDINAL' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('CARDINAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('LONGWORD' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('INTEGER' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('INTEGER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('WORD' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('QWORD' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('QWORD' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('BOOLEAN' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('BOOLEAN' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('CHAR' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('CHAR' ,{$ifdef FPC}@{$endif}AllwaysTrue);

View File

@ -1088,6 +1088,7 @@ function TPascalParserTool.ReadTilProcedureHeadEnd(
proc specifiers with parameters: proc specifiers with parameters:
message <id or number>; message <id or number>;
external; external;
external <id>;
external name <id>; external name <id>;
external <id or number> name <id>; external <id or number> name <id>;
external <id or number> index <id>; external <id or number> index <id>;
@ -1174,8 +1175,6 @@ begin
if UpAtomIs('NAME') or UpAtomIs('INDEX') then begin if UpAtomIs('NAME') or UpAtomIs('INDEX') then begin
ReadNextAtom; ReadNextAtom;
ReadConstant(true,false,[]); ReadConstant(true,false,[]);
end else begin
RaiseException('"name" expected, but '+GetAtom+' found');
end; end;
end; end;
end else if AtomIsChar('[') then begin end else if AtomIsChar('[') then begin

View File

@ -278,6 +278,7 @@ function SecondarySelection: TClipboard;
function Clipboard(ClipboardType: TClipboardType): TClipboard; function Clipboard(ClipboardType: TClipboardType): TClipboard;
function SetClipboard(ClipboardType: TClipboardType; function SetClipboard(ClipboardType: TClipboardType;
NewClipboard: TClipboard): TClipboard; NewClipboard: TClipboard): TClipboard;
procedure FreeAllClipboards;
function RegisterClipboardFormat(const Format: string): TClipboardFormat; function RegisterClipboardFormat(const Format: string): TClipboardFormat;
@ -375,6 +376,13 @@ begin
Result:=PredefinedClipboardFormat(pcfDelphiComponent); Result:=PredefinedClipboardFormat(pcfDelphiComponent);
end; end;
procedure FreeAllClipboards;
var AClipboardType: TClipboardType;
begin
for AClipboardType:=Low(TClipboardType) to High(TClipboardType) do
FreeAndNil(FClipboards[AClipboardType]);
end;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
procedure InternalInit; procedure InternalInit;
@ -390,10 +398,8 @@ begin
end; end;
procedure InternalFinal; procedure InternalFinal;
var AClipboardType: TClipboardType;
begin begin
for AClipboardType:=Low(TClipboardType) to High(TClipboardType) do FreeAllClipboards;
FClipboards[AClipboardType].Free;
end; end;
initialization initialization
@ -401,11 +407,14 @@ initialization
finalization finalization
InternalFinal; InternalFinal;
end. end.
{ {
$Log$ $Log$
Revision 1.8 2002/03/11 23:22:46 lazarus
MG: added TPicture clipboard support
Revision 1.7 2002/03/09 11:55:13 lazarus Revision 1.7 2002/03/09 11:55:13 lazarus
MG: fixed class method completion MG: fixed class method completion

View File

@ -290,6 +290,8 @@ type
procedure LoadFromStream(Stream: TStream); virtual; abstract; procedure LoadFromStream(Stream: TStream); virtual; abstract;
procedure SaveToStream(Stream: TStream); virtual; abstract; procedure SaveToStream(Stream: TStream); virtual; abstract;
procedure LoadFromLazarusResource(const ResName: String); virtual; abstract; procedure LoadFromLazarusResource(const ResName: String); virtual; abstract;
procedure LoadFromClipboardFormat(FormatID: TClipboardFormat); virtual; abstract;
procedure SaveToClipboardFormat(FormatID: TClipboardFormat); virtual; abstract;
constructor Create; // virtual; constructor Create; // virtual;
property Empty: Boolean read GetEmpty; property Empty: Boolean read GetEmpty;
property Height: Integer read GetHeight write SetHeight; property Height: Integer read GetHeight write SetHeight;
@ -396,7 +398,7 @@ type
end; end;
EInvalidGraphic=class(Exception); EInvalidGraphic = class(Exception);
TCanvas = class(TPersistent) TCanvas = class(TPersistent)
@ -497,8 +499,8 @@ type
private private
FRefCount: Integer; FRefCount: Integer;
protected protected
procedure Reference; procedure Reference; // increase reference count
procedure Release; procedure Release; // decrease reference count
procedure FreeHandle; virtual; abstract; procedure FreeHandle; virtual; abstract;
property RefCount: Integer read FRefCount; property RefCount: Integer read FRefCount;
end; end;
@ -622,7 +624,11 @@ var
***************************************************************************) ***************************************************************************)
implementation implementation
uses Controls;
uses Controls, ClipBrd;
const
GraphicsFinalized: boolean = false;
type type
TBitmapCanvas = class(TCanvas) TBitmapCanvas = class(TCanvas)
@ -741,12 +747,22 @@ end;
{$I canvas.inc} {$I canvas.inc}
{$I pixmap.inc} {$I pixmap.inc}
initialization
finalization
GraphicsFinalized:=true;
FreeAndNil(PicClipboardFormats);
FreeAndNil(PicFileFormats);
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.28 2002/03/11 23:22:46 lazarus
MG: added TPicture clipboard support
Revision 1.27 2002/03/11 20:36:34 lazarus Revision 1.27 2002/03/11 20:36:34 lazarus
MG: fixed parser for multiple variant identifiers MG: fixed parser for multiple variant identifiers

View File

@ -18,14 +18,14 @@ end;
constructor TClipboard.Create(AClipboardType: TClipboardType); constructor TClipboard.Create(AClipboardType: TClipboardType);
begin begin
//writeln('[TClipboard.Create] A ',ClipboardTypeName[AClipboardType]); //writeln('[TClipboard.Create] A ',ClipboardTypeName[AClipboardType],' Self=',HexStr(Cardinal(Self),8));
inherited Create; inherited Create;
FClipboardType:=AClipboardType; FClipboardType:=AClipboardType;
end; end;
destructor TClipboard.Destroy; destructor TClipboard.Destroy;
begin begin
//writeln('[TClipboard.Destroy] A ',ClipboardTypeName[ClipboardType]); //writeln('[TClipboard.Destroy] A ',ClipboardTypeName[ClipboardType],' Self=',HexStr(Cardinal(Self),8));
OnRequest:=nil; // this will notify the owner OnRequest:=nil; // this will notify the owner
if FAllocated then begin if FAllocated then begin
ClipboardGetOwnership(ClipboardType,nil,0,nil); ClipboardGetOwnership(ClipboardType,nil,0,nil);
@ -594,6 +594,9 @@ end;
{ {
$Log$ $Log$
Revision 1.7 2002/03/11 23:22:46 lazarus
MG: added TPicture clipboard support
Revision 1.6 2002/03/09 11:55:13 lazarus Revision 1.6 2002/03/09 11:55:13 lazarus
MG: fixed class method completion MG: fixed class method completion

View File

@ -11,10 +11,13 @@ type
end; end;
TPicFileFormatsList = class(TList) TPicFileFormatsList = class(TList)
// list of TPicFileFormat
public public
constructor Create; constructor Create;
destructor Destroy; override; procedure Clear; override;
procedure Delete(Index: Integer);
procedure Add(const Ext, Desc: String; AClass: TGraphicClass); procedure Add(const Ext, Desc: String; AClass: TGraphicClass);
function GetFormat(Index: integer): PPicFileFormat;
function FindExt(Ext: string): TGraphicClass; function FindExt(Ext: string): TGraphicClass;
function FindClassName(const AClassname: string): TGraphicClass; function FindClassName(const AClassname: string): TGraphicClass;
procedure Remove(AClass: TGraphicClass); procedure Remove(AClass: TGraphicClass);
@ -30,30 +33,42 @@ begin
Add('ico', 'Icon', TIcon); Add('ico', 'Icon', TIcon);
end; end;
destructor TPicFileFormatsList.Destroy; procedure TPicFileFormatsList.Clear;
var var i: integer;
I: Integer; P: PPicFileFormat;
p: PPicFileFormat;
begin begin
for I := 0 to Count-1 do begin for i:=0 to Count-1 do begin
p:=PPicFileFormat(Pointer(Items[I])); P:=GetFormat(i);
Dispose(p); Dispose(P);
end; end;
inherited Destroy; inherited Clear;
end;
procedure TPicFileFormatsList.Delete(Index: Integer);
var P: PPicFileFormat;
begin
P:=GetFormat(Index);
Dispose(P);
inherited Delete(Index);
end; end;
procedure TPicFileFormatsList.Add(const Ext, Desc: String; procedure TPicFileFormatsList.Add(const Ext, Desc: String;
AClass: TGraphicClass); AClass: TGraphicClass);
var var
NewRec: PPicFileFormat; NewFormat: PPicFileFormat;
begin begin
New(NewRec); New(NewFormat);
with NewRec^ do begin with NewFormat^ do begin
Extension := AnsiLowerCase(Ext); Extension := AnsiLowerCase(Ext);
GraphicClass := AClass; GraphicClass := AClass;
Description := Desc; Description := Desc;
end; end;
inherited Add(NewRec); inherited Add(NewFormat);
end;
function TPicFileFormatsList.GetFormat(Index: integer): PPicFileFormat;
begin
Result:=PPicFileFormat(Items[Index]);
end; end;
function TPicFileFormatsList.FindExt(Ext: string): TGraphicClass; function TPicFileFormatsList.FindExt(Ext: string): TGraphicClass;
@ -76,9 +91,9 @@ function TPicFileFormatsList.FindClassName(
var var
I: Integer; I: Integer;
begin begin
for I := Count-1 downto 0 do // search backwards so that new formats will be found first
begin for I := Count-1 downto 0 do begin
Result := PPicFileFormat(Items[I])^.GraphicClass; Result := GetFormat(I)^.GraphicClass;
if AnsiLowerCase(Result.ClassName) = AnsiLowerCase(AClassname) then if AnsiLowerCase(Result.ClassName) = AnsiLowerCase(AClassname) then
Exit; Exit;
end; end;
@ -86,18 +101,15 @@ begin
end; end;
procedure TPicFileFormatsList.Remove(AClass: TGraphicClass); procedure TPicFileFormatsList.Remove(AClass: TGraphicClass);
// remove all file formats which inherits from ACLass
var var
I: Integer; I: Integer;
P: PPicFileFormat; P: PPicFileFormat;
begin begin
for I := Count-1 downto 0 do for I := Count-1 downto 0 do begin
begin P := GetFormat(I);
P := PPicFileFormat(Items[I]);
if P^.GraphicClass.InheritsFrom(AClass) then if P^.GraphicClass.InheritsFrom(AClass) then
begin
Dispose(P);
Delete(I); Delete(I);
end;
end; end;
end; end;
@ -111,12 +123,10 @@ begin
Filters := ''; Filters := '';
C := 0; C := 0;
for I := Count-1 downto 0 do begin for I := Count-1 downto 0 do begin
P := PPicFileFormat(Items[I]); P := GetFormat(I);
if P^.GraphicClass.InheritsFrom(GraphicClass) and (P^.Extension <> '') then if P^.GraphicClass.InheritsFrom(GraphicClass) and (P^.Extension <> '') then
with P^ do with P^ do begin
begin if C <> 0 then begin
if C <> 0 then
begin
Descriptions := Descriptions + '|'; Descriptions := Descriptions + '|';
Filters := Filters + ';'; Filters := Filters + ';';
end; end;
@ -131,22 +141,115 @@ begin
['All files', Filters, Descriptions]); ['All files', Filters, Descriptions]);
end; end;
//------------------------------------------------------------------------------
type
PPicClipboardFormat = ^TPicClipboardFormat;
TPicClipboardFormat = record
GraphicClass: TGraphicClass;
FormatID: TClipboardFormat;
end;
TPicClipboardFormats = class(TList)
// list of TPicClipboarFormat
public
constructor Create;
procedure Clear; override;
procedure Delete(Index: Integer);
function GetFormat(Index: integer): PPicClipboardFormat;
procedure Add(AFormatID: TClipboardFormat; AClass: TGraphicClass);
function FindFormat(FormatID: TClipboardFormat): TGraphicClass;
procedure Remove(AClass: TGraphicClass);
end;
constructor TPicClipboardFormats.Create;
begin
inherited Create;
Add(PredefinedClipboardFormat(pcfBitmap), TBitmap);
Add(PredefinedClipboardFormat(pcfPixmap), TPixmap);
Add(PredefinedClipboardFormat(pcfIcon), TIcon);
end;
procedure TPicClipboardFormats.Clear;
var i: integer;
P: PPicClipboardFormat;
begin
for i:=0 to Count-1 do begin
P:=GetFormat(i);
Dispose(P);
end;
inherited Clear;
end;
procedure TPicClipboardFormats.Delete(Index: Integer);
var P: PPicClipboardFormat;
begin
P:=GetFormat(Index);
Dispose(P);
inherited Delete(Index);
end;
function TPicClipboardFormats.GetFormat(Index: integer): PPicClipboardFormat;
begin
Result:=PPicClipboardFormat(Items[Index]);
end;
procedure TPicClipboardFormats.Add(AFormatID: TClipboardFormat;
AClass: TGraphicClass);
var NewFormat: PPicClipboardFormat;
begin
New(NewFormat);
with NewFormat^ do begin
GraphicClass:=AClass;
FormatID:=AFormatID;
end;
end;
function TPicClipboardFormats.FindFormat(
FormatID: TClipboardFormat): TGraphicClass;
var
I: Integer;
P: PPicClipboardFormat;
begin
for I := Count-1 downto 0 do begin
P:=GetFormat(i);
if P^.FormatID=FormatID then begin
Result := P^.GraphicClass;
Exit;
end;
end;
Result := nil;
end;
procedure TPicClipboardFormats.Remove(AClass: TGraphicClass);
var
I: Integer;
begin
for I := Count-1 downto 0 do
if GetFormat(i)^.GraphicClass.InheritsFrom(AClass) then
Delete(i);
end;
//------------------------------------------------------------------------------
const const
PictureFileFormats: TPicFileFormatsList = nil; PicClipboardFormats: TPicClipboardFormats = nil;
PicFileFormats: TPicFileFormatsList = nil;
function GetPicFileFormats: TPicFileFormatsList; function GetPicFileFormats: TPicFileFormatsList;
begin begin
if PictureFileFormats = nil then if (PicFileFormats = nil) and (not GraphicsFinalized) then
PictureFileFormats := TPicFileFormatsList.Create; PicFileFormats := TPicFileFormatsList.Create;
Result := PictureFileFormats; Result := PicFileFormats;
end; end;
{function GetPicClipboardFormats: TPicClipboardFormats; function GetPicClipboardFormats: TPicClipboardFormats;
begin begin
if PicClipboardFormats = nil then if (PicClipboardFormats = nil) and (not GraphicsFinalized) then
PicClipboardFormats := TPicClipboardFormats.Create; PicClipboardFormats := TPicClipboardFormats.Create;
Result := PicClipboardFormats; Result := PicClipboardFormats;
end;} end;
//--TPicture-------------------------------------------------------------------- //--TPicture--------------------------------------------------------------------
@ -155,7 +258,7 @@ constructor TPicture.Create;
begin begin
inherited Create; inherited Create;
GetPicFileFormats; GetPicFileFormats;
//GetClipboardFormats; GetPicClipboardFormats;
end; end;
destructor TPicture.Destroy; destructor TPicture.Destroy;
@ -221,22 +324,25 @@ end;
procedure TPicture.SetGraphic(Value: TGraphic); procedure TPicture.SetGraphic(Value: TGraphic);
var var
NewGraphic: TGraphic; NewGraphic: TGraphic;
ok: boolean;
begin begin
NewGraphic := nil; NewGraphic := nil;
if Value <> nil then if Value <> nil then begin
begin
NewGraphic := TGraphicClass(Value.ClassType).Create; NewGraphic := TGraphicClass(Value.ClassType).Create;
NewGraphic.Assign(Value); NewGraphic.Assign(Value);
NewGraphic.OnChange := @Changed; NewGraphic.OnChange := @Changed;
NewGraphic.OnProgress := @Progress; NewGraphic.OnProgress := @Progress;
end; end;
ok:=false;
try try
FGraphic.Free; FGraphic.Free;
FGraphic := NewGraphic; FGraphic := NewGraphic;
Changed(Self); Changed(Self);
except ok:=true;
NewGraphic.Free; finally
raise; // this try..finally construction will in case of an exception
// not alter the error backtrace output
if not ok then NewGraphic.Free;
end; end;
end; end;
@ -279,36 +385,38 @@ begin
end; end;
procedure TPicture.LoadFromClipboardFormat(FormatID: TClipboardFormat); procedure TPicture.LoadFromClipboardFormat(FormatID: TClipboardFormat);
{var var
NewGraphic: TGraphic; NewGraphic: TGraphic;
GraphicClass: TGraphicClass;} GraphicClass: TGraphicClass;
begin begin
{ GraphicClass := ClipboardFormats.FindFormat(FormatID); GraphicClass := PicClipboardFormats.FindFormat(FormatID);
if GraphicClass = nil then if GraphicClass = nil then
InvalidGraphic(@SUnknownClipboardFormat); raise EInvalidGraphic.Create('Unsupported clipboard format: '
+ClipboardFormatToMimeType(FormatID));
NewGraphic := GraphicClass.Create; NewGraphic := GraphicClass.Create;
try try
NewGraphic.OnProgress := Progress; NewGraphic.OnProgress := @Progress;
NewGraphic.LoadFromClipboardFormat(AFormat, AData, APalette); NewGraphic.LoadFromClipboardFormat(FormatID);
except except
NewGraphic.Free; NewGraphic.Free;
raise; raise;
end; end;
FGraphic.Free; FGraphic.Free;
FGraphic := NewGraphic; FGraphic := NewGraphic;
FGraphic.OnChange := Changed; FGraphic.OnChange := @Changed;
Changed(Self);} Changed(Self);
end; end;
procedure TPicture.SaveToClipboardFormat(FormatID: TClipboardFormat); procedure TPicture.SaveToClipboardFormat(FormatID: TClipboardFormat);
begin begin
if FGraphic <> nil then
FGraphic.SaveToClipboardFormat(FormatID);
end; end;
function TPicture.SupportsClipboardFormat(FormatID: TClipboardFormat): Boolean; function TPicture.SupportsClipboardFormat(FormatID: TClipboardFormat): Boolean;
begin begin
Result:=false; Result := GetPicClipboardFormats.FindFormat(FormatID) <> nil;
end; end;
procedure TPicture.Assign(Source: TPersistent); procedure TPicture.Assign(Source: TPersistent);
@ -332,13 +440,13 @@ end;
procedure TPicture.RegisterClipboardFormat(FormatID: TClipboardFormat; procedure TPicture.RegisterClipboardFormat(FormatID: TClipboardFormat;
AGraphicClass: TGraphicClass); AGraphicClass: TGraphicClass);
begin begin
GetPicClipboardFormats.Add(FormatID, AGraphicClass);
end; end;
class procedure TPicture.UnRegisterGraphicClass(AClass: TGraphicClass); class procedure TPicture.UnRegisterGraphicClass(AClass: TGraphicClass);
begin begin
if GetPicFileFormats <> nil then GetPicFileFormats.Remove(AClass); if PicFileFormats <> nil then PicFileFormats.Remove(AClass);
//if ClipboardFormats <> nil then ClipboardFormats.Remove(AClass); if PicClipboardFormats <> nil then PicClipboardFormats.Remove(AClass);
end; end;
procedure TPicture.Changed(Sender: TObject); procedure TPicture.Changed(Sender: TObject);
@ -358,25 +466,25 @@ var
GraphicClassName: Shortstring; GraphicClassName: Shortstring;
NewGraphic: TGraphic; NewGraphic: TGraphic;
GraphicClass: TGraphicClass; GraphicClass: TGraphicClass;
ok: boolean;
begin begin
Stream.Read(GraphicClassName[0], 1); Stream.Read(GraphicClassName[0], 1);
Stream.Read(GraphicClassName[1], length(GraphicClassName)); Stream.Read(GraphicClassName[1], length(GraphicClassName));
GraphicClass := GetPicFileFormats.FindClassName(GraphicClassName); GraphicClass := GetPicFileFormats.FindClassName(GraphicClassName);
NewGraphic := nil; NewGraphic := nil;
if GraphicClass <> nil then if GraphicClass <> nil then begin
begin
NewGraphic := GraphicClass.Create; NewGraphic := GraphicClass.Create;
ok:=false;
try try
NewGraphic.ReadData(Stream); NewGraphic.ReadData(Stream);
except ok:=true;
NewGraphic.Free; finally
raise; if not ok then NewGraphic.Free;
end; end;
end; end;
FGraphic.Free; FGraphic.Free;
FGraphic := NewGraphic; FGraphic := NewGraphic;
if NewGraphic <> nil then if NewGraphic <> nil then begin
begin
NewGraphic.OnChange := @Changed; NewGraphic.OnChange := @Changed;
NewGraphic.OnProgress := @Progress; NewGraphic.OnProgress := @Progress;
end; end;
@ -405,15 +513,14 @@ procedure TPicture.DefineProperties(Filer: TFiler);
var var
Ancestor: TPicture; Ancestor: TPicture;
begin begin
if Filer.Ancestor <> nil then if Filer.Ancestor <> nil then begin
begin
Result := True; Result := True;
if Filer.Ancestor is TPicture then if Filer.Ancestor is TPicture then begin
begin
Ancestor := TPicture(Filer.Ancestor); Ancestor := TPicture(Filer.Ancestor);
Result := not ((Graphic = Ancestor.Graphic) or Result := not ((Graphic = Ancestor.Graphic)
((Graphic <> nil) and (Ancestor.Graphic <> nil) and or ((Graphic <> nil) and (Ancestor.Graphic <> nil)
Graphic.Equals(Ancestor.Graphic))); and Graphic.Equals(Ancestor.Graphic))
);
end; end;
end end
else Result := Graphic <> nil; else Result := Graphic <> nil;

View File

@ -1,3 +1,5 @@
// included by graphics.pp
{ TSharedImage } { TSharedImage }
procedure TSharedImage.Reference; procedure TSharedImage.Reference;
@ -7,13 +9,14 @@ end;
procedure TSharedImage.Release; procedure TSharedImage.Release;
begin begin
if Pointer(Self) <> nil then if Pointer(Self) <> nil then begin
begin
Dec(FRefCount); Dec(FRefCount);
if FRefCount = 0 then if FRefCount = 0 then begin
begin
FreeHandle; FreeHandle;
Free; Free;
end; end;
end; end;
end; end;
// included by graphics.pp

View File

@ -1064,6 +1064,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.26 2002/03/11 23:22:46 lazarus
MG: added TPicture clipboard support
Revision 1.25 2002/03/08 16:16:55 lazarus Revision 1.25 2002/03/08 16:16:55 lazarus
MG: fixed parser of end blocks in initialization section added label sections MG: fixed parser of end blocks in initialization section added label sections