delphi

What is the simplest way to work with associative strings (key/values)?

I have a lot of constants that are somehow related, at some point I need to pair them, something like this: const key1 = '1'; key2 = '2'; key3 = '3'; value1 = 'a'; value2 = 'b'; value3 = 'c'; I want to avoid doing: if MyValue = key1 then Result := value1; I know how to do it with string lists using: MyStringList.Add(k...

DUnit Testing in a Midas/DataSnap project

How does one setup DUnit Testing in a Midas/DataSnap project in Delphi 2006 Edit How does one set up a Dunit Test into a TRemoteDataModule The project wizard in Delphi 2006 does not work with TRemoteDataModule ...

"Application" global variable not recognized

I work on a large project in Delphi 5. Today, after merging two branches of the app together, one of the hundreds of units, UnitMain (the main form's unit, would you guess) stopped recognizing the Application global. This is a rather bizarre problem - I could get the program to compile by defining Application: TApplication in UnitMain, ...

Serial port WriteFile() freeze

I have a simple application, which should send a single byte to a serial port once a minute. But sometimes, from some strange reason, it freezes somewhere in the WriteFile() function. Both sw and hw flow controls are turned off. I've googled some stuff about pending read operations performed from another threads, but I believe this is no...

What are good uses for class helpers?

Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass. So, what are good uses for class helpers? ...

SSIS Debugging Performance

I’m using SSIS to synchronize data between two databases. I’ve used SSIS and DTS in the past, but I generally write an application for things of this nature (I’m coder and it just comes easier to me). In my package I use a SQL Task that returns about 15,000 rows. I’ve hooked that up to a Foreach Container, and within that I assign the r...

How do I include a newline character in a string in Delphi?

I want to create a string that spans multiple lines to assign to a Label Caption property. How is this done in Delphi? ...

View output of 'print' statements using ADOConnection in Delphi

Some of my MS SQL stored procedures produce messages using the 'print' command. In my Delphi 2007 application, which connects to MS SQL using TADOConnection, how can I view the output of those 'print' commands? Key requirements: 1) I can't run the query more than once; it might be updating things. 2) I need to see the 'print' results e...

How do I get PNGs to work in D2009?

One of Delphi 2009's advertised features was PNG support. That's great, because the Unicode issues break the pngimage.pas library I was using before. Only problem is, I can't find the Delphi 2009 version. Anyone know what it's called, and how difficult it is to migrate existing pngimage.pas-based code to the new library? ...

How do I fill a Delphi set?

If I have a type defined as a set of an enumerated type, it's easy to create an empty set with [], but how do I create a full set? EDIT: Yeah, the obvious solution is to use a for loop. That's also a really bad solution if there's another way. Does anyone know of a way that'll work in constant time? ...

How to stop long executing threads gracefully?

I have a threading problem with Delphi. I guess this is common in other languages too. I have a long process which I do in a thread, that fills a list in main window. But if some parameters change in the mean time, then I should stop current executing thread and start from the beginning. Delphi suggests terminating a thread by setting Te...

Can someone explain Anonymous methods to me?

Delphi 2009, among some cool stuff, has also just got Anonymous methods. I've seen the examples, and the blog posts regarding anonymous methods, but I don't get them yet. Can someone explain why I should be excited? ...

Delphi database: Setting up an array of ADT fields at runtime

I'm using an in-memory dataset to represent an array of objects. I've got most of the code figured out to fill the dataset at runtime, but part of my object contains a dynamic array of TPoint records, and I have no idea how to set up the dataset and the loading code to make that work. I know a TPoint can be represented by an ADT field,...

How can I get the TNMHTTP Get method to respond on a redirect

I'm using TNMHTTP in Delphi to retrieve the code from a webpage. The code is relatively simple: NMHTTP1 := TNMHTTP.Create(Self); NMHTTP1.InputFileMode := FALSE; NMHTTP1.OutputFileMode := FALSE; NMHTTP1.ReportLevel := Status_Basic; NMHTTP1.TimeOut := 3000; URL := 'http://www....'; NMHTTP1.Get(URL); S := NMHTTP1.Body; I am catching ex...

Is it worth caching objects created by Delphi's Memory Manager?

I have an application that creates, and destroys thousands of objects. Is it worth caching and reusing objects, or is Delphi's memory manager fast enough that creating and destroying objects multiple times is not that great an overhead (as opposed to keeping track of a cache) When I say worth it, of course I'm looking for a performance b...

Delphi: Why does "use debug DCUs" become ineffective if I'm using packages in my project?

I'm building a project that uses the JVCL plugin system, which relies on Delphi packages, and ever since I added it to my project, debugging has become a nightmare because I'm no longer able to step-trace into the source of any VCL or RTL units. They're all marked as gray dots in the debugger, (when the relevant functions appear at all ...

Why does Delphi's memory manager report false memory leaks at shutdown?

I'm getting the memory leak message upon shutdown, saying that I'm leaking 3 of a certain object. Two problems with that, though. It only happens intermittently. I can run my program, go through the exact same series of steps, (open a data file, display it, and shut down again,) and sometimes the message will show up and sometimes it...

How do you do a global search and replace in all the files in Delphi 2006 project

Help !!! I have just spent about 10 minutes looking for a way to do a search and replace over all the files in Delphi 2006 project. Please can you tell how to do it ...

Display the call stack in a Delphi Win32 application

I'd like to display a stack trace in an error dialog in Delphi 2007 (Win32). Ideally, I'd like something like this: try //do something except on e : exception do begin //rollback a transaction or whatever i need to do here MessageDlg('An error has occurred!' + #13#10 + e.Message + #13#10 + ...

Hosting the .NET runtime in a Delphi Program

I was looking into using some .NET code from within a Delphi program, I will need to make my program extensible using .net assemblies and predefined functions (I already support regular DLLs). After a lot of searching online, I found Managed-VCL, but I'm not ready to pay $250 for what I need, I also found some newsgroups with code that...