Leaderboard
Popular Content
Showing content with the highest reputation on 04/05/22 in all areas
-
Can undefined function result point to valid/used data in memory?
Stefan Glienke replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
From my experience it never does that - if you have 3 different lines with function calls returning a string the compiler will generate 3 distinct hidden local variables. Even if it's guaranteed they will never be used both such as calling different string returning functions in both branches of an if or in a case. To understand what Peter showed before and how strings (and other managed type) results are handled look at this code: function Test: string; begin Result := Result + 'hello'; end; procedure Main; var s: string; begin s := Test; s := Test; s := Test; Writeln(s); end; var s: string; i: Integer; begin // case 1 Main; // case 2 s := Test; s := Test; s := Test; Writeln(s); // case 3 for i := 1 to 3 do s := Test; Writeln(s); end. 1. When you assign the string result to a local variable the compiler directly passes the local variable as that hidden result var parameter - hence you will see the output 'hellohellohello' 2. When you assign the string result to a global variable (or a field of an object) the compiler generates distinct hidden variables for each occurence of the call - three in this case - they are also initialized to zero like any explicit variable. It then assigns that to s. This is why you will see 'hello' 3. When doing multiple calls in a loop the compiler had only generated one hidden variable - of course which will be reused for each call - now again you will see 'hellohellohello' -
v3.3.0 Added HeightMultiplier property to TSkLabel to change the default line height; Added tag properties to TCustomWordsItem of TSkLabel; Added TItemClickedMessage to intercept the OnClick of all TCustomWordsItem of TSkLabel controls; Improvements in the OnClick triggering of TSkLabel items; Fixed many issues in Windows when using Skia4Delphi Canvas (including combobox dropdown); Fixed wrong colors in iOS with services when using Skia4Delphi Canvas: IFMXTakenImageService, IFMXCameraService, IFMXPhotoLibrary and IFMXShareSheetActionsService; Fixed effects and filters issue in Metal when using Skia4Delphi Canvas; Fixed wrong text size when using Skia4Delphi Canvas (fixing problems with TMemo and TTMSFMXHTMLText); Fixed AV in TSkLabel when the text of a TWordsItem starts with a sLineBreak; Fixed case-insensitive of image formats when saving images; Fixed wrong draws with stroke thickness zero when using Skia4Delphi Canvas; Fixed black screen startup on iOS in simple forms with only shapes when using Skia4Delphi Canvas; Fixed specific cases of performance issues in Windows when using Skia4Delphi Canvas; Fixed projects of RAD Studio 11; Fixed popup menu exception in rasterization mode when using Skia4Delphi Canvas; Fixed modulate color problem before RAD Studio 11.1 (which involves TintColor and TintIconColor properties on mobile); Minor improvements and fixes. Github: github.com/skia4delphi/skia4delphi Website: skia4delphi.org
-
OT: without the "IDE" word the name of this topiс would be some kind of historical fact 🙂
-
Can undefined function result point to valid/used data in memory?
PeterBelow replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
A function return value of type string as well as other compiler-managed types (e.g. dynamic arrays) is actually implemented as an additional Var parameter, so your function would be equivalent to procedure SwitchCase(const aStr: string; var Result:string); The compiler initializes the string variable passed for Result at the point of call, so it will always be valid. It is not guaranteed to be nil (string.empty), though. The compiler may reuse another hidden local variable used previously in the calling method. Such things are documented in the Delphi Language guide, see https://docwiki.embarcadero.com/RADStudio/Sydney/en/Program_Control_(Delphi) -
Can undefined function result point to valid/used data in memory?
Fr0sT.Brutal replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Any allocations give you previously unused memory blocks, if that wouldn't be true even primitive Hello world app would randomly crash -
Doesn't this mean that if you have two devices accessing the same database, they can create duplicate AssetKeys? I prefer to use auto incremented ID fields in the database. If I was being security minded - I would also add GUID identities per row so that it would be much harder to abuse Id values in illegitimate queries if the keys are exposed in a web or REST UI. MS SQL example CREATE TABLE [dbo].[t_company_code]( [CoyId] [int] IDENTITY(1,1) NOT NULL, [CoyCode] [nchar](3) NOT NULL [CoyCreated] [datetime] NOT NULL ) ON [PRIMARY]; GO ALTER TABLE [dbo].[t_company_code] ADD CONSTRAINT [DF_t_company_code_Created] DEFAULT (getdate()) FOR [CoyCreated]; GO CREATE TABLE [dbo].[t_assets]( [AssetId] [int] IDENTITY(1,1) NOT NULL, [CoyId] [int] NOT NULL, [Description] [nchar](63), [AssetCreated] [datetime] NOT NULL ) ON [PRIMARY]; GO ALTER TABLE [dbo].[t_assets] ADD CONSTRAINT [DF_t_Asset_Created] DEFAULT (getdate()) FOR [AssetCreated]; GO -- You would then use a view to join them CREATE VIEW [dbo].[v_CoyAssets] AS SELECT dbo.t_company_code.CoyId, dbo.t_company_code.CoyCode, dbo.t_company_code.CoyCreated, dbo.t_assets.AssetId, dbo.t_assets.Description, dbo.t_assets.AssetCreated FROM dbo.t_company_code INNER JOIN dbo.t_assets ON dbo.t_company_code.CoyId = dbo.t_assets.CoyId; GO and do a select from the view SELECT CoyCode, AssetId from v_CoyAssets order by CoyCode, AssetId;
-
Can undefined function result point to valid/used data in memory?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Delphi strings are managed types so they are never ill-defined in the way that unmanaged types can be before first assignment. Note that this assumes correct practise. So if you use GetMem rather than New to allocate memory for a managed type then the above statement is not correct, but then doing that would be incorrect practise. -
EULA declined installing 11.1 with Network Named license
Remy Lebeau replied to Lachlan Gemmell's topic in General Help
Same reasons all of my VMs were XP, until I was forced to start making Win7 VMs. Same -
Class not instantiated ... but method executed
Dalija Prasnikar replied to DelphiUdIT's topic in Algorithms, Data Structures and Class Design
Executing method on nil reference is actually a language feature. But such method must be static and you must not access any instance fields if instance is nil. One such method is TObject.Free that can be safely called on nil reference, because it checks whether object is nil before calling other code, in this case virtual destructor that cannot be executed on nil instance. procedure TObject.Free; begin if Self <> nil then Destroy; end; Additional explanation how static method dispatching works can be found here https://dalijap.blogspot.com/2021/07/virtual-methods-in-delphi.html -
Class not instantiated ... but method executed
Fr0sT.Brutal replied to DelphiUdIT's topic in Algorithms, Data Structures and Class Design
Methods are just routines with implicit 1st argument set to Self. If you're not using Self inside them, they will work. Try to add some internal string field and show it inside Ghost, then you'll get what you expect -
v3.3.1 Fixed TSkLabel click in Vcl; Fixed bitmaps starting with garbage when using Skia4Delphi Canvas; Fixed AV in TSkLabel and TSkTextLayout in specific cases involving $13 char; Fixed AV drawing uninitialized bitmaps when using Skia4Delphi Canvas;
-
I do! I actually blogged about it: Do you know Build Groups? There you can find instructions to solve your problem.
-
You are working too much...
-
There is no way for Python to know about the objects/functions in your delphi program. You have to create some classes and register them with the Delphi4Python to expose them to the python side. These can be your real classes in your application (not advised IMHO), or "bridge" classes that just expose functions to python. Then, in your implementation of the bridge methods, you call methods/functions on the delphi side.
-
It depends on whether the drive is formatted as NTFS or FAT32. See https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-times
-
Micro optimization: IN vs OR vs CASE
Stefan Glienke replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
The point that others already have expressed is that despite being interested in a topic as performance improvement so low level (as in instruction-level instead of algorithmic level) you seem to lack some important knowledge to do so such as assembly - it does not require as much as it does to write assembly code but to understand it in order to be able to look at the code in the debugger and see that some comparisons are apples and bananas. I did not even read through your code but simply placed a breakpoint into your IsIN function and noticed that it contained a function call to System.SetElem (that even was the first time I have ever seen that function being called so a TIL for me). Why was that the case? Because you are not using consts here but variables. Had you simply made consts for all those IDs the code would have almost as fast as the IsOR which does not suffer to extra function calls but from memory reads (not noticeable in the benchmark because its all in L1 cache already). On my CPU InOR is still a little faster than IsIN which is due to the fact how the compiler builds the in - you can see that for yourself in the disassembly and then look at instruction timings, read up on macro-operation fusion and data dependency For reference, this is the assembly for the two functions when using consts Project1.dpr.40: Result := aID in [xControlsRec.ButtonID, xControlsRec.FormID, xControlsRec.ListBoxID, xControlsRec.TabControlID, xControlsRec.ComboBoxID]; 004CEE7C 83E802 sub eax,$02 004CEE7F 7417 jz $004cee98 004CEE81 83E802 sub eax,$02 004CEE84 7412 jz $004cee98 004CEE86 83E802 sub eax,$02 004CEE89 740D jz $004cee98 004CEE8B 83E802 sub eax,$02 004CEE8E 7408 jz $004cee98 004CEE90 83E802 sub eax,$02 004CEE93 7403 jz $004cee98 004CEE95 33C0 xor eax,eax 004CEE97 C3 ret 004CEE98 B001 mov al,$01 Project1.dpr.41: end; 004CEE9A C3 ret 004CEE9B 90 nop Project1.dpr.45: Result := (aID = xControlsRec.ButtonID) or (aID = xControlsRec.FormID) or (aID = xControlsRec.ListBoxID) or (aID = xControlsRec.TabControlID) or (aID = xControlsRec.ComboBoxID); 004CEE9C 83F802 cmp eax,$02 004CEE9F 7417 jz $004ceeb8 004CEEA1 83F804 cmp eax,$04 004CEEA4 7412 jz $004ceeb8 004CEEA6 83F806 cmp eax,$06 004CEEA9 740D jz $004ceeb8 004CEEAB 83F808 cmp eax,$08 004CEEAE 7408 jz $004ceeb8 004CEEB0 83F80A cmp eax,$0a 004CEEB3 7403 jz $004ceeb8 004CEEB5 33C0 xor eax,eax 004CEEB7 C3 ret 004CEEB8 B001 mov al,$01 Project1.dpr.46: end; 004CEEBA C3 ret Depending on the number of IDs you have it might be worth using power of two and bitmasks or an enum directly because that would only require one cmp/test making the function twice as fast and perfect for inlining which would then also eliminate the function call overhead at all. -
Hi ! I've just published the source code in Pascal/Delphi of "Vidi Language" v0.2-alpha: https://github.com/davidberneda/Vidi It includes a parser/compiler and a simple ide/debugger for a new programming language (Vidi). This is a toy-experiment project in a very early stage. Attached pdf reference, same here: https://github.com/davidberneda/Vidi/blob/master/documentation/Vidi_Language_Reference.md regards david Vidi_Language_Reference.pdf
-
iOS, Metal, Bitmaps, RGB becomes BGR?
sjordi replied to John van de Waeter's topic in Cross-platform
Did you try to move the metal initialization into the .dpr file? I think it's mandatory. Something like in this example (to adapt for your need) {$IF defined(MACOS)} if TCustomContextMetal.IsMetalSupported then GlobalUseMetal := True; {$ENDIF} Application.Initialize; Application.CreateForm(TFormMain, FormMain); Application.Run; I faced several problems when in the main application, it didn't work or even produced errors. Someone here told me that, according to the documentation this has to be set into the DPR file. -
I've just tried your suggestion, and it works perfectly. I don't think I would ever have thought to look under .Model for a SelectText method. It even scrolls the line into view, and it works when the memo is ReadOnly too. Thank you Lajos!
-
I´m still annoyed with the fact that not even a running Delphi is able to appropriately deal with DST changes while running. "No, all those files didn´t change... the time did."