Bernard
-
Content Count
48 -
Joined
-
Last visited
-
Days Won
1
Posts posted by Bernard
-
-
I have had a bit of fun with the OpenAI chat bot.
It is very impressive.
Here is a snippet of what I asked.
ME : Can you now produce delphi code that has inline variables to count to 10?Certainly! Here is some Delphi code that uses inline variables to count from 1 to 10:procedure CountToTen; var I: Integer; begin for I := 1 to 10 do begin writeln(I); end; end; begin CountToTen; end.
This code defines a procedure called
CountToTen
that uses a loop to count from 1 to 10. The loop variableI
is declared as an inline variable using thevar
keyword. The loop itself is afor
loop, which is a common way to count a fixed number of times in Delphi. The loop prints each value ofI
to the console using thewriteln
function.You can run this code by saving it to a file with a
.dpr
extension and then compiling and running it using the Delphi compiler. The output of the program will be the numbers from 1 to 10, each on a separate line.ME: The Delphi language in 10.3 allows more flexibility in the declaration of local variables. The new inline variable declaration syntax allows you to declare the variable directly in a code block (allowing also multiple symbols as usual).Yes, that is correct. In Delphi 10.3 and later versions, it is possible to use inline variable declarations to declare variables directly within a code block, rather than having to declare them at the beginning of the block using thevar
keyword. This can make the code more concise and easier to read, as the variable declarations are closer to where the variables are used.Here is an example of using inline variable declarations to count from 1 to 10:
procedure CountToTen; begin for var I := 1 to 10 do begin writeln(I); end; end; begin CountToTen; end.
In this example, the loop variable
I
is declared using an inline variable declaration within thefor
loop. The variable is then used within the loop to print each value ofI
to the console.Inline variable declarations can be used to declare multiple variables at once, as well. For example:
procedure CountToTen; begin for var I := 1, J := 1 to 10 do begin writeln(I, ' ', J); end; end; begin CountToTen; end.
In this case, the loop declares two inline variables,
I
andJ
, which are both initialized to 1. The loop will run 10 times, and on each iteration, the values ofI
andJ
will be printed to the console.I hope this helps! Let me know if you have any questions or need further clarification.
Me : In your last example there was an error. you cannot have two variables in a for loop. Your first example was correct.You are correct that it is not possible to use multiple variables in the loop control part of afor
loop in Delphi. In my previous response, I included an example that attempts to do this, but it is not valid Delphi code.I apologize for the error in my previous response. Here is the correct version of the example, which only uses a single loop variable:
procedure CountToTen; begin for var I := 1 to 10 do begin writeln(I); end; end; begin CountToTen; end.
This code will correctly count from 1 to 10 and print each number to the console.
Again, I apologize for the mistake in my previous response. Please let me know if you have any further questions.
The output is not always correct.
But it is fun to play with.
- 1
-
Thanks for the fix. Was tearing my hair out on a customer site with no internet connectivity and no mobile.
Drove a mile up the road found the fix and it saved the day.
-
.Net import still producing empty list in latest version "Delphi 11.1"
-
Thanks I will do that.
-
22 minutes ago, Stano said:I personally always use amInsertBefore. The user quickly finds out and arranges accordingly. Of course, the problem is when the row has to go to the end. Then he must move two rows.
Sender.MoveTo(Sender.FocusedNode, Sender.DropTargetNode, amInsertBefore, False);
Yes this was the issue I was trying to fix and the above code sorts it by detecting the direction of the drag.
-
I have been looking to find the best way to move rows in a VirtualTreeview and want to check that this is the best way
I put this code into the Minimal VT Demo
Depending on the drag direction I want to either move the row to position above or below the drop position.
It works but it requires setting up a global mouse position vtStartDragPoint.
Is there a more elegant way?
procedure TMainForm.VSTDragAllowed(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
begin
Allowed := True;
end;procedure TMainForm.VSTDragDrop(Sender: TBaseVirtualTree; Source: TObject; DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
Nodes: TNodeArray;
Attachmode: TVTNodeAttachMode;
begin
Effect := DROPEFFECT_MOVE;
var vtEndDragPoint := Mouse.CursorPos;
if vtStartDragPoint.y < vtEndDragPoint.y then
Attachmode:= amInsertAfter
else
Attachmode:= amInsertBefore;
Nodes:= vst.GetSortedSelection(false);
VST.MoveTo(Nodes[0], Sender.DropTargetNode, Attachmode, false);
end;procedure TMainForm.VSTDragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
begin
Accept := True;
end;procedure TMainForm.VSTStartDrag(Sender: TObject; var DragObject: TDragObject);
begin
vtStartDragPoint := Mouse.CursorPos;
end; -
If the strings are all in one file then notepad++ and a macro or two should work.
-
Hi all,
So I had been looking forward to some juicy update for this version of Delphi.
Looking at the roadmap I thought they have this one in the bag for me.
2 things I was looking forward to were..
1) Delphi Language Extensions for increasingly powerfull coding
2) Math performance improvements to increase your application speed
Do these come in the form of later updates...
- 1
-
Has there been an improvement in maths performance?
-
Is there a list of language enhancements?
-
Thank you both for the feedback.
This info should help 🙂
-
Hello Everyone,
I have been moving to a keyboard mouse free interface on a machine. I have introduced a Touchscreen interface on a machine running Windows 10 Pro.
Issue.
On the screen there are a few buttons that jog motors.When you press the key it will not register unless you move (wiggle) your finger about on the screen.
So the functionality (on touch screen with finger) I am looking for is...
Press and hold button. Motor starts moving.
Release button. Motor stops.
Thank you. -
I did not know that. Makes sense. Thanks
-
I came accross an issue when assigning values to an 'array of word' earlier
This works
var
WordArray : TArray<Word>;
begin
setlength(WordArray, 10);
WordArray := [0, 7323, 0, 7224, 0, 7124, 0, 7024, 0, 7004];
end;This works
var
WordArray : TArray<Word>;
begin
setlength(WordArray, 10);WordArray := [0, word(73232), 0, 7224, 0, 7124, 0, 7024, 0, 7004];
end;
This does not work
var
WordArray : TArray<Word>;
begin
setlength(WordArray, 10);WordArray := [0, 73232, 0 ,7224, 0, 7124, 0, 7024, 0, 7004];
end;
[dcc32 Error] TestArray.pas(28): E1012 Constant expression violates subrange bounds
Can someone explain why the above code is not accepted. For curious reasons.
I am stupid I see why I was outside the max range of Word.
-
I have a half baked component that accepts metric or imperial.
Half baked because
in metric mode it works in mm only
In Imperial mode it works in inches only.
It does not display fraction format but accepts it
so these are all valid input
6'3"
5m23cm
1 1/5M
3 1/2"
3' 1/2"
12ga
If anyone wants to help improve the code let me know, and I will stick it on Github.
-
I am worried about missing VCL styles as I use the "Windows 10 Slate Gray" and designed icons to contrast nicely with the colors (not a graphics guy and I spent more time at this than I needed). Can anyone confirm it is in the latest install.
-
19 minutes ago, Stefan Glienke said:"Get your conditional jumps and error handling garbage outta my hot loop, kay?"
Nice one.
32bit release
Pascal lookup (Stefan): 1449
64bit release
Pascal lookup (Stefan): 1434
Quote -
This has turned into a great thread for learning about speed improvements by simple tweaks.
Using Sets instead of Case
function HexToBinMahdi5(const HexValue: string): string; type TChar4 = array [0 .. 3] of Char; PChar4 = ^TChar4; const Table1: array ['0' .. '9'] of TChar4 = ('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001'); Table2: array ['a' .. 'f'] of TChar4 = ('1010', '1011', '1100', '1101', '1110', '1111'); Table3: array ['A' .. 'F'] of TChar4 = ('1010', '1011', '1100', '1101', '1110', '1111'); var HexDigit: Char; P: PChar4; begin SetLength(Result, Length(HexValue) * 4); P := PChar4(Result); for var i: integer := low(HexValue) to high( HexValue ) do begin if HexValue[i] in [ '0' .. '9'] then P^ := Table1[HexValue[i]] else if HexValue[i] in [ 'a' .. 'f'] then P^ := Table2[HexValue[i]] else if HexValue[i] in [ 'A' .. 'F'] then P^ := Table3[HexValue[i]] else raise EConvertError.CreateFmt('Invalid hex digit ''%s'' found in ''%s''', [HexDigit, HexValue]); Inc(P); end; end;
Compiled 32bit Release
Pascal lookup (Heff): 4091
Pascal lookup (Mahdi): 4107
Pascal lookup (Mahdi 3 Table): 4264
Pascal lookup (Mahdi 3 Table Set): 3665
Pascal lookup (Mahdi 3 Table Set Local Var loop): 2951- 2
-
Speed up the HexToBinMahdi function by adding a 3rd table and removing any calculations
function HexToBinMahdi(const HexValue: string): string;
type
TChar4 = array [0 .. 3] of Char;
PChar4 = ^TChar4;
const
Table1: array ['0' .. '9'] of TChar4 = ('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001');
Table2: array ['a' .. 'f'] of TChar4 = ('1010', '1011', '1100', '1101', '1110', '1111');
Table3: array ['A' .. 'F'] of TChar4 = ('1010', '1011', '1100', '1101', '1110', '1111');
var
HexDigit: Char;
P: PChar4;
begin
SetLength(Result, Length(HexValue) * 4);
P := PChar4(Result);
for HexDigit in HexValue do
begin
case HexDigit of
'0' .. '9':
P^ := Table1[HexDigit];
'a' .. 'f':
P^ := Table2[HexDigit];
'A' .. 'F':
P^ := Table3[HexDigit];
else
raise EConvertError.CreateFmt('Invalid hex digit ''%s'' found in ''%s''', [HexDigit, HexValue]);
end;
Inc(P);
end;
end;Pascal lookup (Heff): 5777
Pascal lookup (Mahdi): 5948
Pascal lookup (Mahdi 2): 5414
asm32: 6800
xmm: 6068 -
Thank you.
Is this problem a that only impacts some installations?
-
I am having this issue in 10.4 update 1. Have you ever managed to find a resolution?
-
On 6/19/2020 at 3:52 PM, Bernard said:Just installed Delphi 10.4 on my main Windows 10 development machine and I still see the same issues. Has anyone else ran the sample in Windows 10 and found the same issues.
Found issue
For anyone having this issue of the Toggle Switch giving issues. I have a funny feeling that it is not just me.
Get an older copy from the latest community edition or your Rio install.
Open the Bitmap Style Designer and open
C:\Users\Public\Documents\Embarcadero\Studio\20.0\Styles\Windows10SlateGray.vsf
Compare it to
C:\Users\Public\Documents\Embarcadero\Studio\21.0\Styles\Windows10SlateGray.vsf
If you look at the toggle switch in the latest update it is not correct.
Hope this helps..
-
On 6/16/2020 at 7:07 PM, Bernard said:Hi All,
Just got a chance to install Delphi 10.4 on my windows 7 Laptop and loaded up a sample.
C:\Users\Public\Documents\Embarcadero\Studio\21.0\Samples\Object Pascal\VCL\ToggleSwitch
I ran it and when I change the VCL style to Windows10Blue or Windows10Dark it displays incorrectly
Anyone else got this.
By the way thanks everyone for the great info on this site
Just installed Delphi 10.4 on my main Windows 10 development machine and I still see the same issues. Has anyone else ran the sample in Windows 10 and found the same issues.
-
On 6/18/2020 at 8:51 AM, Sherlock said:Windows 7 is no longer supported, nor should it be. Why support anything even the original manufacturer only supports grudgingly and for a price? As a consequence applications will run, but eye candy will not be as sweet as intended. That seems to be a good compromise to me.
I have a customer base that run windows 7 PCs with machine control software on them. These machines require periodic software updates. Some of these guys who have the machines are not technical at all. They know how to turn machuines on and off and use the machine software. Some of them have no internet so updates are sent on USB. That is why Win 7 support is a requirement.
Delphi beta testing a "premium" privilege?
in Tips / Blogs / Tutorials / Videos
Posted
Is there a roadmap for the next version?