delphi-2007

When does Delphi honor `inline` and when not?

做~自己de王妃 提交于 2019-12-05 00:59:26
问题 I was tying to optimize a piece of code that has this construct: while (i > 0) do begin Dec(i); This looks inefficient, so I tried to do this: while (Dec(i) >= 0) do begin That doesn't work because Dec is a procedure and not a function. So I rewrite it to: procedure Withloop; var .... function Decr(var a: integer): integer; inline; begin Dec(a); Result:= a; end; ... while (Decr(i) >= 0) do begin But this gets compiled into: SDIMAIN.pas.448: while (Decr(i) >= 0) do begin 00468EE5 8BC4 mov eax

In Delphi, how can you check if an IInterface reference implements a derived but not explicitly-supported interface?

痞子三分冷 提交于 2019-12-05 00:29:52
If I have the following interfaces and a class that implements them - IBase = Interface ['{82F1F81A-A408-448B-A194-DCED9A7E4FF7}'] End; IDerived = Interface(IBase) ['{A0313EBE-C50D-4857-B324-8C0670C8252A}'] End; TImplementation = Class(TInterfacedObject, IDerived) End; The following code prints 'Bad!' - Procedure Test; Var A : IDerived; Begin A := TImplementation.Create As IDerived; If Supports (A, IBase) Then WriteLn ('Good!') Else WriteLn ('Bad!'); End; This is a little annoying but understandable. Supports can't cast to IBase because IBase is not in the list of GUIDs that TImplementation

Why does this string have a reference count of 4? (Delphi 2007)

自作多情 提交于 2019-12-04 22:57:01
This is a very Delphi specific question (maybe even Delphi 2007 specific). I am currently writing a simple StringPool class for interning strings. As a good little coder I also added unit tests and found something that baffled me. This is the code for interning: function TStringPool.Intern(const _s: string): string; var Idx: Integer; begin if FList.Find(_s, Idx) then Result := FList[Idx] else begin Result := _s; if FMakeStringsUnique then UniqueString(Result); FList.Add(Result); end; end; Nothing really fancy: FList is a TStringList that is sorted, so all the code does is looking up the string

How can I avoid refresh with TWebBrowser

情到浓时终转凉″ 提交于 2019-12-04 19:09:45
I have a TWebBrowser component that show a Google maps page. The problem is that when user press F5 the page refresh and page reloads. This cause javascript variables to reinitialize and get out of sync with Delphi and a scripting error dialog appear, 'undefined' is null or not an object. I want to stop refresh from the user. I tried this event for OnBeforeNavigate2: procedure TNewOrganizationForm.mapAddressBeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool); begin inherited; Cancel := Assigned

In Delphi in my DLL do I have to allocate the return pchar of a function

北城余情 提交于 2019-12-04 18:53:59
问题 I have a DLL in which I have a function that returns a pchar. (as to avoid having to use borlndmm) What I was doing originally was casting a string as a pchar and returning that Result := pChar(SomeFuncThatReturnsString) But I was getting expected results 90% of the time and the other times I would get back nothing. I then got to thinking that I needed to allocate the memory for the pchar and that doing it my original way was having a pchar point to memory that was not always going to be what

Stringlist with delimiter as a string?

假如想象 提交于 2019-12-04 17:49:40
I have an attribute called HistoryText in a object that is stored as a string. I want to show all rows in a grid. I should be able to delete and edit rows in the grid. The format is: 16.5.2003-$-12:09-$-anna-$-Organization created 2.6.2005-$-13:03-$-jimmy-$-Organization edited 19.12.2005-$-13:33-$-madeleine-$-Organization edited So each row have 4 fields, date, time, user, and message with a delimiter string as '-$-'. As the delimiter a string and not a char it cannot be assigned to the stringlists delimiter property. I have a routine to extract the string to a Stringlist: procedure

What is the fastest way for reading huge files in Delphi?

怎甘沉沦 提交于 2019-12-04 13:53:06
问题 My program needs to read chunks from a huge binary file with random access. I have got a list of offsets and lengths which may have several thousand entries. The user selects an entry and the program seeks to the offset and reads length bytes. The program internally uses a TMemoryStream to store and process the chunks read from the file. Reading the data is done via a TFileStream like this: FileStream.Position := Offset; MemoryStream.CopyFrom(FileStream, Size); This works fine but

Converting LogFont height to Font size in points

安稳与你 提交于 2019-12-04 07:25:43
I have a LOGFONT structure. Now all i'd like to do is get the associated font size in points from the LOGFONT height. When the mapping mode is mm_Text (which it usually is), and when the lfHeight field is positive, it already gives the height in points. When it's negative, the units are pixels. MSDN for LogFont gives you the formula to convert between them: lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); There are 72 points per inch. GetDeviceCaps tells you the number of pixels per inch on a given device. Invert the formula to get pixels from points: PointSize := MulDiv(

Which is current correct indy and open ssl versions to use with delphi2007

若如初见. 提交于 2019-12-04 06:23:38
问题 I'm using indy components with D2007 and try to list subject of messages from a imap mailbox. I downloaded and installed current indy new version 10.6.0.5039 (installing x100 packages) and tried with various openssl dll versions (32bit on xp machine, copied both in system32 dir and in my app dir) but always got "could not load ssl library" error. Could someone tell me the right indy dcl package and openssl dll to use with D2007? Using function WhichFailedToLoad i get the result: "SSL_CTX_set

Delphi 2007 : How to Set TSAWARE?

谁说我不能喝 提交于 2019-12-04 04:22:17
In Delphi 2009 and up you can add this line to your project .dpr to set the TSAWARE PE flag in your application executable: {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE} I thought (wrongly) that this syntax is not supported in Delphi 2007. I have an application that I cannot port from 2007 to a newer Delphi version just yet (the task is underway, but it will not be done in the next few months). Update it was simply that Windows must be added to the project .dpr also. My guess is that you are missing the Windows unit from your .dpr file's uses clause. Add that and you will be