-
Content Count
1200 -
Joined
-
Last visited
-
Days Won
16
Everything posted by FPiette
-
function ExtractDomain(const URL : String) : String; var I, J : Integer; begin I := Pos('://', URL); if I <= 0 then I := 1 else Inc(I, 3); J := Pos('/', URL, I); if J <= 0 then begin Result := Copy(URL, I, MAXINT); Exit; end; Result := Copy(URL, I, J - I); end; procedure TForm1.Button1Click(Sender: TObject); var Index : Integer; Dict : TDictionary<String, Integer>; URL : String; Domain : String; Value : Integer; begin Dict := TDictionary<String, Integer>.Create(10000); try ListBox1.Items.BeginUpdate; try for Index := ListBox1.Items.Count - 1 downto 0 do begin URL := ListBox1.Items[Index]; if URL = '' then begin ListBox1.Items.Delete(Index); continue; end; Domain := ExtractDomain(Trim(UpperCase(URL))); if Dict.TryGetValue(Domain, Value) then begin // Domain already found, delete from ListBox ListBox1.Items.Delete(Index); continue; end; // Domain not seen before, add to dictionary and don't remove from list Dict.Add(Domain, 0); end; finally ListBox1.Items.EndUpdate; end; finally FreeAndNil(Dict); end; end; This will check for domain by ignoring character casing and ignoring the protocol. You may adept this to a TStrings easily. I used a dictionary because you said you have 10K items. A dictionary should be faster than a simple list when there are a lot of items but I have not checked how many items are required so that dictionary is faster than list.
-
Not sure I understand what you want to do! Please clarify the context. By the way, the email file format depend on the source (mail client) you use to drop the file. Outlook will drop a .msg file.
-
{$POINTERMATH ON} ?
-
@Mark ElderFinally, what will you do? I ask because you have not reacted to any answer you received. And by the way, if you don't want to write a full message, at least click on the like button of each answer you like. The like button is the heart icon on the right side of each message. Thanks.
-
InterlockedCompareExchange can be used to implement a spinlock. When using shared memory, this will work interprocess.
- 22 replies
-
- synchronization
- multitasking
-
(and 1 more)
Tagged with:
-
I think ADO components are included in PRO version as well.
-
How do I enumerate all properties of a Variant?
FPiette replied to Phil Brinkle's topic in General Help
Undocumented doesn't mean it has not documentation inside the exe/dll. The proof is that my function show the list of functions. Try to import the DLL in Delphi as it is a type library (Delphi Menu Component / Import component / Import a Type Library. If it doesn't appear in the list, click the Add button and select your dll. If it doesn't work, try adding it as an ActiveX instead. -
I think so provided the data is in shared memory.
- 22 replies
-
- synchronization
- multitasking
-
(and 1 more)
Tagged with:
-
How do I enumerate all properties of a Variant?
FPiette replied to Phil Brinkle's topic in General Help
Thanks. If you like my answer, please mark it as such (The heart icon on the right side of my answer). Maybe you have a type library ? If you import it into Delphi, you'll have all the information. -
How do I enumerate all properties of a Variant?
FPiette replied to Phil Brinkle's topic in General Help
Yes, you can. Basically, you have to call GetTypeInfoCount(), GetTypeInfo(), GetTypeAttr() and other functions (All documented by Microsoft). Here is a function to list all method names including property getter/setter. Similar code can enumerate argument list, argument data types and return value data type. procedure DisplayMethodNames( const DispIntf : IDispatch; const IntfName : String; Strings : TStrings); var Count : Integer; TypeInfo : ITypeInfo; TypeAttr : PTypeAttr; FuncDesc : PFuncDesc; HR : HRESULT; I : Integer; FuncName : WideString; begin if IntfName <> '' then Strings.Add(IntfName); Count := 0; HR := DispIntf.GetTypeInfoCount(Count); if Failed(HR) or (Count = 0) then Exit; HR := DispIntf.GetTypeInfo(0, 0, TypeInfo); if Succeeded(HR) and (TypeInfo <> nil) then begin TypeAttr := nil; HR := TypeInfo.GetTypeAttr(TypeAttr); if Succeeded(HR) and (TypeAttr <> nil) then begin for I := 0 to TypeAttr.cFuncs - 1 do begin FuncDesc := nil; HR := TypeInfo.GetFuncDesc(I, FuncDesc); if Succeeded(HR) and (FuncDesc <> nil) then begin TypeInfo.GetDocumentation(FuncDesc.memid, @FuncName, nil, // DocString, nil, // HelpContext nil); // HelpFile if Length(FuncName) <> 0 then Strings.Add(Format(' %-3d %s', [I, FuncName])); TypeInfo.ReleaseFuncDesc(FuncDesc); end; end; TypeInfo.ReleaseTypeAttr(TypeAttr); end; end; end; -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Your are right: an event is a kind of callback. But not all callbacks are events. In Delphi there is a pattern for the events. I explained that pattern in a few previous messages and @Fr0sT.Brutal expressed it again using different words. -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
I really like event very much. I don't see any use case which requires a callback. Do you? -
There are several TriggerSendData. In which class do you need it?
-
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
No exactly. You need to pass the arguments for the call: if Assigned(FOnGetSearchTextLine) then FOnGetSearchTextLine(Self, ADataIdx, Result); -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Where is the "thanks" button? As I said: hover the "like" button and you'll see it. The like button is the heart icon on the bottom right corner of a message. -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Instead of writing "thanks" in the message, you should click the "thanks" button (Hover the "like" button to see it). -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
The idea is that when no event handler is assigned, the component/class/object works correctly. That's why they are procedure and returned values are passed as var argument, just like I have done in my example: function TSearchFrom.GetSearchTextLine(ADataIdx : Integer) : String; begin Result := ''; // This will be the search line if no event handler assigned if Assigned(FOnGetSearchTextLine) then FOnGetSearchTextLine(Self, ADataIdx, Result); end; Another design tips is that if an event is triggered several times, a procedure is created for that: procedure TSearchForm.TriggerGetSearchTextLine(ADataIdex : Integer; var SearchText : String); begin if Assigned(FOnGetSearchTextLine) then FOnGetSearchTextLine(Self, ADataIdx, Result); end; and then you'll write: function TSearchFrom.GetSearchTextLine(ADataIdx : Integer) : String; begin Result := ''; // This will be the search line if no event handler assigned TriggerGetSearchTextLine(ADataIdx, Result); end; -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
OK, I understand better. Your design is correct. You need an event in the search form to get text line at given index. Each frame initialize the search form event to a handler. TGetSearchTextLineEvent = procedure function (Sender : TObject; aDataIdx: integer; var TextLine : String) of object; TSearchForm = class(TForm) private FDataIdx : Integer; FOnGetSearchTextLine : TGetSearchTextLineEvent; function GetSearchTextLine(ADataIdx : Integer) : String; public function Search(ADataIdx : Integer) : String; property OnGetSearchTextLine : TGetSearchTextLineEvent read FOnGetSearchTextLine write FOnGetSearchTextLine; end; function TSearchFrom.GetSearchTextLine(ADataIdx : Integer) : String; begin Result := ''; // This will be the search line if no event handler assigned if Assigned(FOnGetSearchTextLine) then FOnGetSearchTextLine(Self, ADataIdx, Result); end; -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
No, they are not events. An event would looks like: TGetSearchTextLineEvent = procedure function (Sender : TObject; aDataIdx: integer; var TextLine : String) of object; Your code is not very clear to me. I understand you have a TFrame which has to do a search and for that, it create and display a form. Right? Why not simply have a function Search in the form, taking what to search in arguments and return search result? No event nor callback required at all. -
Common callback functions, or not?
FPiette replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Usually, with Delphi we use events which are a form of callbacks which are 1st category citizen in Delphi language. Callbacks as you are doing will of course work in Delphi but are more C/C++ style. I usually define all event types where they are used and duplicate it at will. Sometimes, I use a unit having "Types" as suffix in his name to put those definitions along with other related data types. -
Maybe a new Win8 or Win10 feature not supported by Win7.
-
Is the missing System.TStringHelper SetChars in Chars property on purpose ?
FPiette replied to Rollo62's topic in RTL and Delphi Object Pascal
In my opinion, using zero based strings is a source of a lot of headaches. I was very upset when Embarcadero introduced that for mobile platform. Now I'm happy they abandoned the idea. -
Is the missing System.TStringHelper SetChars in Chars property on purpose ?
FPiette replied to Rollo62's topic in RTL and Delphi Object Pascal
Better for you, but not for user of the code page feature... -
SSL GetRemoteFile not transferring the whole image
FPiette replied to Brian Culverwell's topic in ICS - Internet Component Suite
I cannot find it. What is the sample project name? Look into the source and see if you can find who wrote it? Where did you have downloaded this sample? Make sure you have the latest ICS source code -
Would be nice if you publish the code you have already tried so that we can review it and even try to make it work without having to invent a full test program.