Questions tagged [delphi]
Delphi is a language for rapid development of native Windows, OS X and iOS applications through use of Object Oriented Pascal. The name also refers to the Delphi IDE, which is used to help edit and debug Delphi projects more efficiently.
76 questions
2
votes
3
answers
182
views
Configurable 'swapping' order of loops
The code below groups a list by either number or letter, as seen below:
1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B, 5A, 5B
or
1A, 2A, 3A, 4A, 5A, 1B, 2B, 3B, 4B, 5B
The option is configurable by the user via ...
1
vote
1
answer
677
views
Delphi - did I understand callbacks correctly?
I am trying to learn callbacks in Delphi (7). Could not find a complete simple tutorial, so I puzzled together a few bits here and there. This is my first attempt, of course trivial.
My form contains ...
3
votes
1
answer
347
views
Delphi function to canonicalize the capitalization in a file path
I'm building a small Delphi application where a user can input a file or directory manually by typing it or by selecting it from a dialog . Since it can be input manually, I want to ensure that I save ...
2
votes
0
answers
404
views
Delphi TIdTCPClient connection pool in a multithread environment
I want to use TIdTCPClient to connect to Redis from a web server application made with Delphi and TWebModule. Currently on ...
2
votes
0
answers
93
views
type in a Postcode and get the address
(I asked this Question in stackoverflow (Delphi) and they suggested that I try here.
Is there a site to submit my Delphi 7 coding to?
Hi I am learning how to build compound components. My latest ...
2
votes
3
answers
141
views
Efficiently calculate the value of an arithmetic sequence
I need to calculate the value for the following function:
$$f(n) = -1 + 2 - 3 + ... + -1^n$$
The time limit to calculate a given value of \$n\$ is less than 1 second. My approach does not meet that ...
3
votes
1
answer
792
views
Basic Color class for both Delphi and Lazarus
Intro
If you want to know, then about 10+ years ago, I started a journey on the (best in my country) color picker for WinXP, later Win7. Since now it is hardly compatible with Win10 and HiDPI (work in ...
4
votes
0
answers
137
views
Animation loop for a sliding puzzle game
I'm building a "sliding puzzle" game. This is the animation code for when you click a Tile.
This "loop" function is running all the time.
When you click a tile, if it's available to move, I set the "...
2
votes
2
answers
158
views
Dephi: faster way to convert a "dirty" string to a number
How can I make this code faster? the string can contain characters such as ", .?#" and possibly others.
...
0
votes
1
answer
618
views
IsValidEmailAddress
I have created this function for Delphi 10.1 Berlin to validate an email address entered by the user:
...
1
vote
1
answer
292
views
Generic function for loading a function from a DLL library
I am trying to write a generic function for loading a function from a DLL library. I am in no way an expert on DLLs, that is why I ask.
We have discussed it first in my Stack Overflow question to ...
4
votes
0
answers
376
views
Code efficiency check for hangman in Delphi
I recently coded a game of hangman and wanted to know,
A: Are there any places it could be more efficient?
B: Are there any things that are distinctly wrong with it, since I know people seem to say ...
3
votes
1
answer
860
views
Noughts and crosses bot in Delphi
I hope someone can guide me in a way to make this code more efficient. Please explain the things you do simply because I'm no pro so more complex things I am unlikely to get.
If you have issues with ...
1
vote
1
answer
1k
views
Enumerating RCData resources from the EXE file which has been launched
I am running Delphi XE6.
I recently integrated all of my read-only language INI files into the executables.
As a consequence, I need to enumerate RCData resources (and then simply filter out the ...
3
votes
1
answer
3k
views
Sending a string from anonymous thread to UI with PostMessage
I am sending a string from an anonymous thread to the UI with PostMessage in the following code:
...
2
votes
0
answers
845
views
Delphi: TFileStream child class with progress event on read/write
i want implement a progress event on TFileStream for read/write operation for assign on it a progress bar.
I have create a clild class (...
3
votes
1
answer
3k
views
Resumable download with System.net.HTTPClient
This is a Delphi class, based on System.net.HTTPClient with a function for downloading a file from a URL and saving on a filename destination:
...
3
votes
0
answers
7k
views
TTimerThread - Threaded timer class
I was inspired by @LU RD's answer to the question: Using VCL TTimer in Delphi console application, and wrote a bit simplified TTimerThread class.
By simplified I ...
2
votes
1
answer
855
views
Semi-Reliable Communications Using UDP
I'm writing a communications library for a class. Part of the requirements is that semi-reliable communications, which leads me to this monstrosity:
...
2
votes
1
answer
4k
views
JPG image resizing
This Delphi (Seattle 10) routine resizes a JPG image if one of its sizes is larger than AMaxDimension pixels, and gives it a compression factor of ...
4
votes
0
answers
93
views
Writing a file sequentially
I've written a procedure which allows serialized writing of a stream. I don't in any way consider this done, but this is the beginning of it. I know there are other implementations out there like this,...
3
votes
0
answers
1k
views
Alternative for Float Animations
In the Firemonkey framework of Delphi, there's a feature called Float Animations, which allows you to control real-time "animation" of float values. However, in the VCL framework, this feature is not ...
2
votes
1
answer
2k
views
Flipping True or False values to save typing and time
I have a few columns in a DBGrid that I want to hide and show at different times depending on what the user wants to view.
Rather than writing the following code;
...
2
votes
0
answers
2k
views
LockBox TwoFish string encryption and decryption
I'm using TurboPower LockBox for the first time, and using the TwoFish algorithm to first encrypt a password, and later retrieve the password by decrypting the generated hash.
I would like to know ...
1
vote
2
answers
218
views
Delphi 2009 interface
I have this code and at the end of it, FastMM shows that there were memory leaks with all the objects of TSinc:
...
11
votes
1
answer
2k
views
Precise timings with low jitter via RDTSC (for x86 and x64)
The Win32 API has a so-called 'high performance counter' (QueryPerformanceCounter() and friends) but often it is neither precise enough nor reliable enough, due to ...
9
votes
1
answer
1k
views
Delphi XE 7 project template for saving / loading form settings
I have developed small test project as a template for production project.
In this template I've found a way that the application saves and loads its own settings (ini-file).
Main Form1 will contain ...
5
votes
1
answer
548
views
Parsing a command line
I've written an object which allows parsing and serializing a command line. I don't in any way consider this done, but this is the beginning of it. I know there are other implementations out there ...
3
votes
0
answers
695
views
Delphi: convenience wrapper for GetSystemTimePreciseAsFileTime()
For some purposes it can be highly desirable to use GetSystemTimePreciseAsFileTime() whenever it is available (i.e. Windows 8+) because the accuracy of ...
2
votes
0
answers
250
views
Write data with updateresources
I have developed this function but I'm not sure if this is the best (secure) way to write in resources without corrupt *.exe in case of fails.
What is the best way to write resources to a *.exe file?
...
3
votes
1
answer
965
views
Binary and linear search methods for a number-guessing game
This is a code written is Pascal (Delphi). It asks the user to think of a number between min_ and max_ and then guesses the ...
2
votes
1
answer
2k
views
Buttons switches in Delphi
I have an action on four buttons. I need to make a down (checked) button if it's pressed and other buttons up (unchecked). My button is TToolButton and the property ...
4
votes
2
answers
2k
views
Validating Card Number in Delphi
As part of processing card payments, before even attempting to process, I need to check and validate the card number to make sure it's valid. For this, I've encapsulated this validation in a record ...
4
votes
1
answer
214
views
Passing variable pointer as string to another function
With Delphi 7 I need to create a TStream variable and use/free it in another part of the code. Unfortunately it cannot be passed as "normal" parameter.
I created a ...
5
votes
1
answer
483
views
Translating array pointer access from C++ to Delphi
I'd like to know if I translated a piece of code correctly from C++ to Delphi. It looks like it is working, but I have a feeling that I'm reading and writing into memory that I'm not supposed to using ...
5
votes
2
answers
5k
views
Write to files in Delphi
I'm doing a program in Delphi, writing in all kinds of files, either text or executable:
...
2
votes
0
answers
635
views
Class derived from TXmlIniFile to save/read to/from XML
I have created this unit containing a class derived from TXmlIniFile. This class uses the common TCustomInifile methods to write to and read from an XML file. It comes from an idea of Chris Rolliston ...
3
votes
1
answer
15k
views
Function to split text
The following pascal function (compiled with Delphi) will split strings. It works perfectly, but how to improve the code? For example, to avoid using the repeat-until loop.
...
3
votes
1
answer
3k
views
Function to find text between two tags
I've just finished this function and wanted to know if anyone know another way to do the same:
...
2
votes
0
answers
740
views
Get local Dropbox path with Delphi XE7
I've put together a function in Delphi XE7 which returns the Dropbox directory path on my machine, as this path can be customized by the user.
This function currently works on my computer, but it ...
3
votes
0
answers
127
views
Single level of abstraction
I am reading the "Clean Code" book and trying refactoring my source code according to the principles "single level of abstraction"/"separation of concerns".
How would you refactor the following code? ...
4
votes
2
answers
9k
views
Converting Delphi colors between TColor, RGB, CMYK, and HSV
I wrote a record which encapsulates conversion of colors between TColor, RGB values, CMYK ...
4
votes
1
answer
453
views
Efficient binary patcher
I am currently working on a little binary patcher. My current code works fine but I do want my code to be optimized (fast) and as clean as possible. Could you all please help me review this?
IDE: ...
3
votes
1
answer
105
views
Validating user's input before creating graph using TChart
The user enters coefficients into input boxes on a form, called GetFunction. Upon clicking an OK button on said form, the input is validated using ...
2
votes
0
answers
3k
views
What's the best approach to achieve two-way communication with TIdTCPServer and TIdTCPClient?
I'm a newbie in Delphi and I'm trying to create a client/server application using INDY. I want to have a server that is capable not only of receiving messages and streaming, but also sending data to ...
6
votes
2
answers
1k
views
Is this an appropriate approach to "tweak" a color to a similar lighter/darker color?
I have written this function for the sole purpose to get a similar color either brighter or darker than any given color, depending on an average lightness/darkness. Essentially, I add up the R/G/B ...
5
votes
1
answer
820
views
Stack-based mini-stack
I've created a MiniStack to assist in removing recursion from routines using a manual stack.
Obviously if the stack is an object it lives on the heap and its ...
8
votes
1
answer
320
views
Factorial using trampolines
I've translated this Java code into Delphi code:
...
24
votes
1
answer
2k
views
Executing large SQL script file with GO statements using ADO
I wrote a small component (still in the works but working) which takes a large SQL script file, splits it into different "blocks" based on GO statements, and executes them one by one.
The only major ...
7
votes
1
answer
445
views
Drawing and Painting a Menu Component
I have produced a working menu component for a project I'm working on, but would like to reduce the amount of code used and improve the methods - especially in the Paint implementation - still further,...