mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 08:29:29 +02:00
* fix for 15509.
* setcount drastically simplified * Capacity now property with setter, to allow shrinking (but only till count) git-svn-id: trunk@14897 -
This commit is contained in:
parent
5e1a09f817
commit
b99d54383c
@ -73,6 +73,7 @@ type
|
||||
function GetCount : integer;
|
||||
procedure SetColor (index:integer; const Value:TFPColor); virtual;
|
||||
function GetColor (index:integer) : TFPColor;
|
||||
procedure SetCapacity (ind : Integer);
|
||||
procedure CheckIndex (index:integer); virtual;
|
||||
procedure EnlargeData; virtual;
|
||||
public
|
||||
@ -86,6 +87,7 @@ type
|
||||
procedure Clear; virtual;
|
||||
property Color [Index : integer] : TFPColor read GetColor write SetColor; default;
|
||||
property Count : integer read GetCount write SetCount;
|
||||
property Capacity : integer read FCapacity write SetCapacity;
|
||||
end;
|
||||
|
||||
TFPCustomImage = class(TPersistent)
|
||||
|
@ -122,23 +122,15 @@ begin
|
||||
end;
|
||||
|
||||
procedure TFPPalette.SetCount (Value:integer);
|
||||
var NewData : PFPColorArray;
|
||||
var
|
||||
O : integer;
|
||||
begin
|
||||
if Value <> FCount then
|
||||
begin
|
||||
if Value > FCapacity then
|
||||
begin
|
||||
O := FCapacity;
|
||||
FCapacity := Value + 8;
|
||||
if FCapacity > 0 then
|
||||
GetMem (NewData, sizeof(TFPColor)*FCapacity)
|
||||
else
|
||||
FData := nil;
|
||||
move (FData^, NewData^, sizeof(TFPColor)*FCount);
|
||||
if O > 0 then
|
||||
FreeMem (FData);
|
||||
FData := NewData;
|
||||
FCapacity := Value+8;
|
||||
Reallocmem(FData,sizeof(TFPColor)*FCapacity);
|
||||
end;
|
||||
for o := FCount to Value-1 do
|
||||
FData^[o] := colBlack;
|
||||
@ -146,6 +138,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFPPalette.SetCapacity (ind : Integer);
|
||||
var o : Integer;
|
||||
begin
|
||||
if ind<count then ind:=count;
|
||||
if ind<>fcapacity then
|
||||
begin
|
||||
fcapacity:=ind;
|
||||
Reallocmem(FData,sizeof(TFPColor)*FCapacity);
|
||||
end;
|
||||
if ind>count then
|
||||
begin
|
||||
for o := FCount to ind-1 do
|
||||
FData^[o] := colBlack;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TFPPalette.IndexOf (const AColor:TFPColor) : integer;
|
||||
begin
|
||||
result := FCount;
|
||||
|
Loading…
Reference in New Issue
Block a user