10 TDuplicates
= (dupIgnore
, dupAccept
, dupError
);
12 TThreadList
= object(TObj
)
15 FLock
: TRTLCriticalSection
;
16 FDuplicates
: TDuplicates
;
18 procedure Init
; virtual;
19 // constructor Create;
20 destructor Destroy
; virtual;//override;
21 procedure Add(Item
: Pointer);
23 function LockList
: PList
;//TList;
24 procedure Remove(Item
: Pointer);
26 property Duplicates
: TDuplicates read FDuplicates write FDuplicates
;
29 PThreadList
=^TThreadList
;
31 function NewThreadList({ACollection: PCollection}): PThreadList
;
35 PCollection
= ^TCollection
;
37 PCollectionItem
= ^TCollectionItem
;
38 TCollectionItem
= object(TObj
)
40 FCollection
: PCollection
;
42 // FACollection:PCollection;
43 function GetIndex
: Integer;
44 procedure SetCollection(Value
: PCollection
);
46 FACollection
:PCollection
;
47 procedure Changed(AllItems
: Boolean);
48 function GetOwner
: PObj
; // override;
49 function GetDisplayName
: string; virtual;
50 procedure SetIndex(Value
: Integer); virtual;
51 procedure SetDisplayName(const Value
: string); virtual;
53 { constructor Create(Collection: TCollection); virtual;
56 procedure Init
; virtual;
57 procedure Assign(Source
: PCollectionItem
);
58 function GetNamePath
: string; //override;
59 property Collection
: PCollection read FCollection write SetCollection
;
60 property ID
: Integer read FID
;
61 property Index
: Integer read GetIndex write SetIndex
;
62 property DisplayName
: string read GetDisplayName write SetDisplayName
;
65 TCollection
= object(TObj
)
67 // FItemClass: TCollectionItemClass;
69 FUpdateCount
: Integer;
72 function GetCount
: Integer;
73 function GetPropName
: string;
74 procedure InsertItem(Item
: PCollectionItem
);
75 procedure RemoveItem(Item
: PCollectionItem
);
77 property NextID
: Integer read FNextID
;
78 { Design-time editor support }
79 function GetAttrCount
: Integer; // dynamic;
80 function GetAttr(Index
: Integer): string; // dynamic;
81 function GetItemAttr(Index
, ItemIndex
: Integer): string; // dynamic;
83 function GetItem(Index
: Integer): PCollectionItem
;
84 procedure SetItem(Index
: Integer; Value
: PCollectionItem
);
85 procedure SetItemName(Item
: PCollectionItem
); virtual;
86 procedure Update(Item
: PCollectionItem
); virtual;
87 property PropName
: string read GetPropName write FPropName
;
88 property UpdateCount
: Integer read FUpdateCount
;
90 { constructor Create(ItemClass: TCollectionItemClass);
93 procedure Init
; virtual;
94 function Add
: PCollectionItem
;
95 procedure Assign(Source
: PObj
); // override;
96 procedure BeginUpdate
; virtual;
98 procedure Delete(Index
: Integer);
99 procedure EndUpdate
; virtual;
100 function FindItemID(ID
: Integer): PCollectionItem
;
101 function GetNamePath
: string; // override;
102 function Insert(Index
: Integer): PCollectionItem
;
103 property Count
: Integer read GetCount
;
104 // property ItemClass: TCollectionItemClass read FItemClass;
105 property Items
[Index
: Integer]: PCollectionItem read GetItem write SetItem
;
107 //Pllection=^ollection;
109 { Collection class that maintains an "Owner" in order to obtain property
110 path information at design-time }
112 POwnedCollection
= ^TOwnedCollection
;
113 TOwnedCollection
= object(TCollection
)
117 function GetOwner
: PObj
; // override;
119 // procedure Init; virtual;
120 { constructor Create(AOwner: TPersistent; ItemClass: TCollectionItemClass);
123 //Plection=^llection;
124 //function Newlection(AOwner: TPersistent; ItemClass: TCollectionItemClass):Plection; type MyStupid20258=DWord;
125 function NewOwnedCollection(AOwner
: PObj
{;
126 ItemClass: TCollectionItemClass}): POwnedCollection
;
127 function NewCollection(Collection
: PCollection
): PCollection
;
128 function NewCollectionItem(ACollection
: PCollection
): PCollectionItem
;
131 PStringStream
=^TStringStream
;
132 TStringStream
=object(TStream
)
134 // FDataString: string;
135 // FPosition: Integer;
136 function GetDataString
:String;
138 procedure SetSize(NewSize
: Longint); //override;
140 // constructor Create(const AString: string);
141 function Read(var Buffer
; Count
: Longint): Longint; //override;
142 function ReadString(Count
: Longint): string;
143 function Seek(Offset
: Longint; Origin
: Word): Longint; //override;
144 function Write(const Buffer
; Count
: Longint): Longint; //override;
145 procedure WriteString(const AString
: string);
146 property DataString
: string read GetDataString
;
149 PStringStreamData
=^TStringStreamData
;
150 TStringStreamData
=packed record
155 function NewStringStream(const AString
: string):PStringStream
;
161 function NewCollectionItem(ACollection
: PCollection
): PCollectionItem
;
162 //constructor TCollectionItem.Create(Collection: PCollection);
166 FACollection
:=ACollection
;
169 // SetCollection(Collection);
172 procedure TCollectionItem
.Init
;
174 SetCollection(FACollection
);//Collection);
177 destructor TCollectionItem
.Destroy
;
183 procedure TCollectionItem
.Changed(AllItems
: Boolean);
185 Item
: PCollectionItem
;
187 if (FCollection
<> nil) and (FCollection
.FUpdateCount
= 0) then
193 FCollection
.Update(Item
);
197 function TCollectionItem
.GetIndex
: Integer;
199 if FCollection
<> nil then
200 Result
:= FCollection
.FItems
.IndexOf(@Self
)
205 function TCollectionItem
.GetDisplayName
: string;
207 // Result := ClassName;
210 function TCollectionItem
.GetNamePath
: string;
212 if FCollection
<> nil then
213 Result
:= Format('%s[%d]', [FCollection
.GetNamePath
, Index
]);
215 Result := ClassName;}
218 function TCollectionItem
.GetOwner
: PObj
;
220 Result
:= FCollection
;
223 procedure TCollectionItem
.SetCollection(Value
: PCollection
);
225 if FCollection
<> Value
then
227 if FCollection
<> nil then
228 FCollection
.RemoveItem(@Self
);
230 Value
.InsertItem(@Self
);
234 procedure TCollectionItem
.SetDisplayName(const Value
: string);
239 procedure TCollectionItem
.SetIndex(Value
: Integer);
243 CurIndex
:= GetIndex
;
244 if (CurIndex
>= 0) and (CurIndex
<> Value
) then
246 FCollection
.FItems
.MoveItem(CurIndex
, Value
);
253 function NewCollection(Collection
: PCollection
): PCollection
;
254 //constructor TCollection.Create(ItemClass: TCollectionItemClass);
260 // FItemClass := ItemClass;
261 FItems := NewList; //TList.Create;
265 procedure TCollection
.Init
;
267 // FItemClass := ItemClass;
268 FItems
:= NewList
; //TList.Create;
271 destructor TCollection
.Destroy
;
274 if FItems
<> nil then
280 function TCollection
.Add
: PCollectionItem
;
282 Result
:= NewCollectionItem(@Self
); //FItemClass.Create(Self);
285 procedure TCollection
.Assign(Source
: PObj
);
289 if TCollection
.AncestorOfObject(Source
) { is TCollection} then
294 for I
:= 0 to PCollection(Source
).Count
- 1 do
295 Add
.Assign(PCollection(Source
).Items
[I
]);
301 // inherited Assign(Source);
304 procedure TCollection
.BeginUpdate
;
309 procedure TCollection
.Changed
;
311 if FUpdateCount
= 0 then
315 procedure TCollection
.Clear
;
317 if FItems
.Count
> 0 then
321 while FItems
.Count
> 0 do
322 PCollectionItem(FItems
.Last
).Free
;
329 procedure TCollection
.EndUpdate
;
335 function TCollection
.FindItemID(ID
: Integer): PCollectionItem
;
339 for I
:= 0 to FItems
.Count
- 1 do
341 Result
:= PCollectionItem(FItems
.Items
[I
]);
342 if Result
.ID
= ID
then
348 function TCollection
.GetAttrCount
: Integer;
353 function TCollection
.GetAttr(Index
: Integer): string;
358 function TCollection
.GetItemAttr(Index
, ItemIndex
: Integer): string;
360 Result
:= Items
[ItemIndex
].DisplayName
;
363 function TCollection
.GetCount
: Integer;
365 Result
:= FItems
.Count
;
368 function TCollection
.GetItem(Index
: Integer): PCollectionItem
;
370 Result
:= FItems
.Items
[Index
];
373 function TCollection
.GetNamePath
: string;
377 // Result := ClassName;
378 // if GetOwner = nil then Exit;
379 // S := GetOwner.GetNamePath;
385 Result
:= S
+ '.' + P
;
388 function TCollection
.GetPropName
: string;
392 // TypeData: PTypeData;
393 // Owner: PObj; //TPersistent;
397 if (Result <> '') or (Owner = nil) or (Owner.ClassInfo = nil) then Exit;
398 TypeData := GetTypeData(Owner.ClassInfo);
399 if (TypeData = nil) or (TypeData^.PropCount = 0) then Exit;
400 GetMem(Props, TypeData^.PropCount * sizeof(Pointer));
402 GetPropInfos(Owner.ClassInfo, Props);
403 for I := 0 to TypeData^.PropCount-1 do
406 if (PropType^^.Kind = tkClass) and
407 (GetOrdProp(Owner, Props^[I]) = Integer(Self)) then
416 function TCollection
.Insert(Index
: Integer): PCollectionItem
;
419 Result
.Index
:= Index
;
422 // Out param is more code efficient for interfaces than function result
423 {procedure GetDesigner(Obj: TPersistent; out Result: IDesignerNotify);
428 if Obj = nil then Exit;
429 Temp := Obj.GetOwner;
432 if (Obj is TComponent) and (csDesigning in TComponent(Obj).ComponentState) then
433 TComponent(Obj).QueryInterface(IDesignerNotify, Result);
437 if (Obj is TComponent) and
438 not (csDesigning in TComponent(Obj).ComponentState) then Exit;
439 GetDesigner(Temp, Result);
443 {function FindRootDesigner(Obj: TPersistent): IDesignerNotify;
445 GetDesigner(Obj, Result);
448 {procedure NotifyDesigner(Self, Item: TPersistent; Operation: TOperation);
450 Designer: IDesignerNotify;
452 GetDesigner(Self, Designer);
453 if Designer <> nil then
454 Designer.Notification(Item, Operation);
457 procedure TCollection
.InsertItem(Item
: PCollectionItem
);
459 // if not (Item is FItemClass) then
460 // TList.Error(@SInvalidProperty, 0);
462 Item
.FCollection
:= @Self
;
467 // NotifyDesigner(Self, Item, opInsert);
470 procedure TCollection
.RemoveItem(Item
: PCollectionItem
);
472 // NotifyDesigner(Self, Item, opRemove);
474 Item
.FCollection
:= nil;
478 procedure TCollection
.SetItem(Index
: Integer; Value
: PCollectionItem
);
480 PCollectionItem(FItems
.Items
[Index
]).Assign(Value
);
483 procedure TCollection
.SetItemName(Item
: PCollectionItem
);
487 procedure TCollection
.Update(Item
: PCollectionItem
);
491 procedure TCollection
.Delete(Index
: Integer);
493 PCollectionItem(FItems
.Items
[Index
]).Free
;
498 function NewOwnedCollection(AOwner
: PObj
{;
499 ItemClass: TCollectionItemClass}): POwnedCollection
;
500 {constructor TOwnedCollection.Create(AOwner: TPersistent;
501 ItemClass: TCollectionItemClass);}
506 // inherited Create(ItemClass);
509 function TOwnedCollection
.GetOwner
: PObj
;
514 procedure TCollectionItem
.Assign(Source
: PCollectionItem
);
516 Collection
:= Source
.Collection
;
517 FID
:= Source
.FID
; // ???
518 Index
:= Source
.Index
;
519 DisplayName
:= Source
.DisplayName
;
522 {constructor TStringStream.Create(const AString: string);
525 FDataString := AString;
528 function TStringStream
.Read(var Buffer
; Count
: Longint): Longint;
530 CData
:PStringStreamData
;
533 Result
:= Length(CData
.FDataString
) - CData
.FPosition
;
534 if Result
> Count
then Result
:= Count
;
535 Move(PChar(@CData
.FDataString
[Data
.FPosition
+ 1])^, Buffer
, Result
);
536 Inc(CData
.FPosition
, Result
);
539 function TStringStream
.Write(const Buffer
; Count
: Longint): Longint;
541 CData
:PStringStreamData
;
545 SetLength(CData
.FDataString
, (CData
.FPosition
+ Result
));
546 Move(Buffer
, PChar(@CData
.FDataString
[Data
.FPosition
+ 1])^, Result
);
547 Inc(CData
.FPosition
, Result
);
550 function TStringStream
.Seek(Offset
: Longint; Origin
: Word): Longint;
552 CData
:PStringStreamData
;
556 soFromBeginning: FPosition := Offset;
557 soFromCurrent: FPosition := FPosition + Offset;
558 soFromEnd: FPosition := Length(FDataString) - Offset;
560 if CData
.FPosition
> Length(CData
.FDataString
) then
561 CData
.FPosition
:= Length(CData
.FDataString
)
562 else if CData
.FPosition
< 0 then CData
.FPosition
:= 0;
563 Result
:= CData
.FPosition
;
566 function TStringStream
.ReadString(Count
: Longint): string;
569 CData
:PStringStreamData
;
574 Len
:= Length(FDataString
) - FPosition
;
575 if Len
> Count
then Len
:= Count
;
576 SetString(Result
, PChar(@FDataString
[FPosition
+ 1]), Len
);
581 procedure TStringStream
.WriteString(const AString
: string);
583 Write(PChar(AString
)^, Length(AString
));
586 procedure TStringStream
.SetSize(NewSize
: Longint);
588 CData
:PStringStreamData
;
593 SetLength(FDataString
, NewSize
);
594 if FPosition
> NewSize
then FPosition
:= NewSize
;
598 function TStringStream
.GetDataString
:String;
600 CData
:PStringStreamData
;
602 Result
:=CData
.FDataString
;
605 function NewStringStream(const AString
: string):PStringStream
;
607 CData
:PStringStreamData
;
609 // New( Result, Create );
610 // Move( StreamMethods, Result.fMethods, Sizeof( TStreamMethods ) );
611 // Result.fPMethods := @Result.fMethods;
612 Result
:=PStringStream(NewMemoryStream
);
617 GetMem(CData
,Sizeof(CData
^));
618 FillChar(CData
^,Sizeof(CData
^),0);
619 Result
.CustomData
:=CData
;
621 CData
.FDataString
:= AString
;
627 procedure TThreadList
.Add(Item
: Pointer);
631 if (Duplicates
= dupAccept
) or
632 (FList
.IndexOf(Item
) = -1) then
634 else if Duplicates
= dupError
then
636 // FList.Error(@SDuplicateItem, Integer(Item));
643 procedure TThreadList
.Clear
;
654 destructor TThreadList
.Destroy
;
656 LockList
; // Make sure nobody else is inside the list.
662 DeleteCriticalSection(FLock
);
666 procedure TThreadList
.Init
;
669 InitializeCriticalSection(FLock
);
670 FList
:= NewList
;//TList.Create;
671 FDuplicates
:= dupIgnore
;
674 function TThreadList
.LockList
: PList
;//TList;
676 EnterCriticalSection(FLock
);
680 procedure TThreadList
.Remove(Item
: Pointer);
690 procedure TThreadList
.UnlockList
;
692 LeaveCriticalSection(FLock
);
695 function NewThreadList({ACollection: PCollection}): PThreadList
;
697 New( Result
, Create
);
700 InitializeCriticalSection(FLock);
701 FList := TList.Create;
702 FDuplicates := dupIgnore;}