Delphi

Find the Minimum Positive Value

五迷三道 提交于 2020-01-03 08:45:53
问题 What's the best algorithm to find the smallest non zero positive value from a fixed number (in this case 3) of values or return 0 if there are no positive questions? My naive approach is below (in Delphi, but feel free to use whatever you like), but I think there's a more elegant way. value1Temp := MaxInt; value2Temp := MaxInt; value3Temp := MaxInt; if ( value1T > 0) then value1Temp := value1; if ( value2 > 0) then value2Temp := value2; if ( value3 > 0) then value3Temp := value3; Result :=

How to create subitems menus under the application name on OSX?

大城市里の小女人 提交于 2020-01-03 08:38:52
问题 How to add TMenuItem under Project1 and above Quit on the screenshot below? I have created a TMenuBar with property UseOSMenu checked. The first TMenuItem I added is the second one in the main bar... 回答1: You can do this by assigning a TMenuBar of IItemsContainer implementing class to the Application.ApplicationMenuItems property. Example: If there was a menu bar component on the form called MenuBar1, then you would just call the following in your forms constructor (or OnCreate). Application

DLL and class in multithreaded application

霸气de小男生 提交于 2020-01-03 08:08:09
问题 I have a class inside my DLL. And this DLL provides an "interface" to create objects of this class and call their methods. Class code (simplified): TLogger = class private // public function AddToLog(sBuf: PWideChar): Word; constructor Create(Name: PWideChar); destructor Destroy; override; end; constructor Create(Name: PWideChar); begin // end; destructor TLogger.Destroy; begin // end; function TLogger.AddToLog(sBuf: PWideChar): Word; var Temp1 : WideString; Temp2 : AnsiString; begin Result :

DLL and class in multithreaded application

青春壹個敷衍的年華 提交于 2020-01-03 08:08:08
问题 I have a class inside my DLL. And this DLL provides an "interface" to create objects of this class and call their methods. Class code (simplified): TLogger = class private // public function AddToLog(sBuf: PWideChar): Word; constructor Create(Name: PWideChar); destructor Destroy; override; end; constructor Create(Name: PWideChar); begin // end; destructor TLogger.Destroy; begin // end; function TLogger.AddToLog(sBuf: PWideChar): Word; var Temp1 : WideString; Temp2 : AnsiString; begin Result :

enable themes for applications

那年仲夏 提交于 2020-01-03 07:30:11
问题 i have an old application (started in delphi 7 in Win XP), now i'm using delphi 2009 (win Vista). If i start a new project all buttons have a rouded edge, but in my old app all buttons have a "square"-shape look. is there any setting that i've missed? thanks 回答1: Under the Project Options in D2009, there is an "Enable runtime themes" option which is ticked by default for new projects but unticked for pre-existing projects. Ticking this adds the manifest file to the EXE's resource, which is

Why is TFormatSettings not behaving as expected?

我的梦境 提交于 2020-01-03 06:58:06
问题 I expect the following code to work: program Project3; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; var FS: TFormatSettings; const DF = 'yyyymmdd'; begin try WriteLn(FormatDateTime(DF, Now)); FS := TFormatSettings.Create; FS.ShortDateFormat := DF; WriteLn(StrToDate('20121219', FS)); ReadLn; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Why is it throwing an exception, saying that '20121219' is not a valid date? Isn't that exactly what passing the

Thread-safe way to increment and return an integer in Delphi

China☆狼群 提交于 2020-01-03 06:53:09
问题 In a single-threaded application I use code like this: Interface function GetNextUID : integer; Implementation function GetNextUID : integer; const cUID : integer = 0; begin inc( cUID ); result := cUID; end; This could of course be implemented as a singleton object, etc. - I'm just giving the simplest possible example. Q: How can I modify this function (or design a class) to achieve the same result safely from concurrent threads? 回答1: You can use the Interlocked* functions: function

SQL OOP problem : Too many actual parameters on output

北慕城南 提交于 2020-01-03 06:44:07
问题 Please help with the following: ERROR : too many actual parameters on calling class procedure line. Main UNIT: procedure TForm1.btnbtbtn1Click(Sender: TObject); var bwagwoord,bemail :boolean ; epos,wagwoord,safvoer :String ; begin Form2.qryreg.Close; form2.qryreg.SQL.Text := 'select * from registertb '; form2.qryreg.open ; epos := edt1.text ; wagwoord := edt2.text ; safvoer := ' '; bemail :=form2.qryreg.locate ('Email',epos,[]); bwagwoord := form2.qryreg.Locate('Wagwoord',wagwoord,[]); Login

Delphi AsyncCalls Deadlock when Terminating the Threads (com+ dll finalization)

爷,独闯天下 提交于 2020-01-03 06:41:10
问题 I have a big Delphi 2007 project, and I use AsyncCall I have extracted and tested the multithreading code in a single console application and everything works fine. My Delphi 2007 project produces a COM DLL and I have some unit tests that are written in C# - mstest that calls the DLL. The unit tests hang quite often randomly (tests passed) and i found out it happens at the AsyncCall unit - finalizatoin section that frees the ThreadPool. destructor TThreadPool.Destroy; var I: Integer; Call:

Work around with Delphi DLL

半城伤御伤魂 提交于 2020-01-03 06:34:27
问题 I have two applications in Delphi for which I don't have any code source: I use an interface from application A to call an DLL file from application B. Example, I usually pass a service number, 200011, from interface A to call DLL file B for a value return. But, recently the application A have changed the variable. I have to add P00200011 to call DLL file B. I have tried to create an DLL C#, but the DLL in B is created with the fastcall convention and I cannot change this DLL file. What are