-
Content Count
407 -
Joined
-
Last visited
-
Days Won
8
Everything posted by Kryvich
-
operator overloding Equal vs Multiply
Kryvich replied to Eugine Savin's topic in RTL and Delphi Object Pascal
@Eugine Savin Is it possible to rewrite your C++ snippet as: MyArray myArr; if (myArr == {0} && myArr == {0, 0}) {} As I understand you need to inline array constants to the Delphi expressions. -
@Mike Torrettinni Check my demo app (attached). Works as needed in Windows 7 (I haven't Win10 here, sorry). Look at the project source: program SplashApp; uses SysUtils, Vcl.Forms, uSplashMain in 'uSplashMain.pas' {Form1}, uSplashForm in 'uSplashForm.pas' {Form5}; {$R *.res} begin Application.Initialize; Form5 := TForm5.Create(nil); try Application.MainFormOnTaskbar := True; Form5.Show; Form5.Update; Application.CreateForm(TForm1, Form1); Sleep(3000); finally Form5.Free; end; Application.Run; end. Form5 is a splash form, and Form1 is a app's main form. Also check menu Project | Options | Application | Forms. The splash Form5 is in the list of available forms (the right list). SplashApp.zip
-
I tried this suggestion for Delphi 7, and it still works in Rio and Windows 7. In TForm5: protected procedure CreateParams(var Params :TCreateParams); override; ... procedure TForm5.CreateParams(var Params: TCreateParams); begin inherited; Params.ExStyle := Params.ExStyle OR WS_EX_APPWINDOW; end;
-
operator overloding Equal vs Multiply
Kryvich replied to Eugine Savin's topic in RTL and Delphi Object Pascal
To tell the compiler the type of operand, I can advise the following: Replace array of Integer with TArray<Integer>. (In 10.3 Rio it is the same type.) Create a helper function: function AsArray(const [ref] Arr: TArray<Integer>): TArray<Integer>; inline; begin Result := Arr; end; ... b := r = AsArray([10]); // It compiles -
If VS is so great, then why RemObjects create Water - their own IDE for Windows?
-
@Alexander Elagin Just in case you need the icons because of change indicators, you can try https://sites.google.com/site/kryvich/kryvichs-editor-status-bars. Works without IDE theming too.
-
Caching with class variables
Kryvich replied to Primož Gabrijelčič's topic in Tips / Blogs / Tutorials / Videos
@Attila Kovacs if typeData.MaxValue > 30 then "change me to UInt64". -
Is it really good practice to create Forms only as needed? Always?
Kryvich replied to Mike Torrettinni's topic in VCL
Have you measured how users work with your program? It's possible that an average user use 5-10 reports (tabs) in one session. Then all controls on other tabs just sit in memory, grab GDI resources without need. It's OK to create the form layouts manually, Delphi has all instruments to make this work easier. But after rising HTML and CSS it has become fashionable to entrust the program with the placement and adjustment of the size of controls on a form. For ex. https://www.delphihtmlcomponents.com/comp.html https://www.delphihtmlcomponents.com/reports.html https://www.devexpress.com/products/vcl/layout/ http://docwiki.embarcadero.com/Libraries/Tokyo/en/FMX.Layouts -
Is it really good practice to create Forms only as needed? Always?
Kryvich replied to Mike Torrettinni's topic in VCL
I presume you didn't put all that controls to the form manually. It's a lot of work. I would use some sort of automation, and create the appropriate controls on the fly when the tab was selected. Then you'll get 3000/50 = 60 controls at a moment. -
Is it really good practice to create Forms only as needed? Always?
Kryvich replied to Mike Torrettinni's topic in VCL
I never see such forms. Is it for flight control center? -
Allocation-Free Collections
Kryvich replied to Erik@Grijjy's topic in Tips / Blogs / Tutorials / Videos
@Stefan Glienke Interesting... Do modern processors can not predict the branch that will be executed in the common case? -
Is it really good practice to create Forms only as needed? Always?
Kryvich replied to Mike Torrettinni's topic in VCL
You're right. A better solution would be to create and initialize a form by request, and then Show(ShowModal)/Close it as needed. The reference to the created form can be saved as a class variable and freed when an application to finish. It makes sense for forms that need to maintain their state. Or for modal dialogs. And you need to ensure that two or more identical forms are not opened at the same time. -
There is option in the project options (Application | Forms) to select what forms to create when an application starts.
-
Allocation-Free Collections
Kryvich replied to Erik@Grijjy's topic in Tips / Blogs / Tutorials / Videos
@Erik@Grijjy The checks can be regulated by the RangeChecks option {R+}. -
Allocation-Free Collections
Kryvich replied to Erik@Grijjy's topic in Tips / Blogs / Tutorials / Videos
A list not allocated in the heap? How is it even possible? Start reading... Good idea! I know where I can try it in my code. -
Generic Dictionary and an inline variable: bug or misuse?
Kryvich posted a topic in RTL and Delphi Object Pascal
Hi, I try to adopt outstanding and free Pas2js transpiler to Delphi language. My main development IDE is Delphi CE Rio, so I decided to try a new Delphi syntax: generic collections and inline variables. And stumbled upon a runtime error. The code (simplified): program TestInlineVarForDictionary; {$APPTYPE CONSOLE} {$R *.res} uses SysUtils, Generics.Collections; procedure TestDictErr; var Dict: TDictionary<string,TObject>; begin Dict := TDictionary<string,TObject>.Create; for var item in Dict do Writeln('Key = ', item.Key, 'Name = ', item.Value.ClassName); end; procedure TestDictOK; var Dict: TDictionary<string,TObject>; item: TPair<string,TObject>; begin Dict := TDictionary<string,TObject>.Create; for item in Dict do Writeln('Key = ', item.Key, 'Name = ', item.Value.ClassName); end; begin try //!!TestDictOK; TestDictErr; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Write('Press Enter to continue...'); Readln; end; end; end. This program causes Exception class $C0000005 with message 'access violation at 0x0040a86e: write of address 0x0040a29e'. Can you confirm it? Is it a bug in the compiler or/and RTL, or am I misusing the new syntax? It's interesting: if you uncomment TestDictOK that does enumeration in old-style, the exception will disappear!- 3 replies
-
- tdictionary
- inline variables
-
(and 2 more)
Tagged with:
-
Generic Dictionary and an inline variable: bug or misuse?
Kryvich replied to Kryvich's topic in RTL and Delphi Object Pascal
OK I have a workaround for this issue. Try to specify a type of the inline variable. procedure TestDictErr_WorkAround; var Dict: TDictionary<string,TObject>; begin Dict := TDictionary<string,TObject>.Create; for var item: TPair<string,TObject> in Dict do Writeln('Key = ', item.Key, ' Name = ', item.Value.ClassName); end; I cannot guarantee that this code will be correctly compiled. But at least there is no the runtime error anymore.- 3 replies
-
- tdictionary
- inline variables
-
(and 2 more)
Tagged with:
-
Generic Dictionary and an inline variable: bug or misuse?
Kryvich replied to Kryvich's topic in RTL and Delphi Object Pascal
Another observation. The exception occurs only if the dictionary has the key and/or value of the string type. If I change it to Integer - the exception disappears. procedure TestDictErr_IntegerKey_OK; var Dict: TDictionary<Integer,TObject>; begin Dict := TDictionary<Integer,TObject>.Create; for var item in Dict do Writeln('Key = ', item.Key, 'Name = ', item.Value.ClassName); end; Well, I just found it. For procedure TestDictOK the compiler generates a pair of calls: call @InitializeRecord call @FinalizeRecord But for procedure TestDictErr it generates only call @FinalizeRecord Program tries to finalize not initialized record and falls. P.S. Is there a bug bounty program for Delphi? :) https://quality.embarcadero.com/browse/RSP-23417- 3 replies
-
- tdictionary
- inline variables
-
(and 2 more)
Tagged with:
-
@haentschman It's always better to have named constants instead of numbers. Say you want to swap 2nd and 6th bits in some structure's field. Then you need to scan all your program and check all places where these bits are used. But if you used an enumeration from the start, you just swap these bits in the declaration: type TMyEnum = (mb0, mb5, mb2, mb3, mb4, mb1, mb6, mb7); Of course instead of mb0, mb1 etc. should be really meaningful names, without numbers.
-
You can write it as If ((b and $01) > 0) or ((b and $08) > 0) or ((b and $80) > 0) then ... Or you can create an enumeration and use meaningful names for each bit. type TMyEnum = (mb0, mb1, mb2, mb3, mb4, mb5, mb6, mb7); TMyBits = set of TMyEnum; // = Byte in size function Test: Byte; var mbs: TMyBits; begin mbs := [mb0, mb3, mb7]; Byte(mbs) := $89; // It's equivalent of mbs := [mb0, mb3, mb7]; if mbs * [mb0, mb3, mb7] <> [] then // If one of bit is set ;//... if mbs * [mb0, mb3, mb7] = [mb0, mb3, mb7] then // If all 3 bits are set ;//... if mbs - [mb0, mb3, mb7] = [] then // If no other bits are set ;//... Include(mbs, mb1); // Set 2nd bit mbs := mbs - [mb3, mb7]; // Unset 4th and 8th bit //etc... Result := Byte(mbs); end; It's always better to deal with clearly named typed variables and constants.
-
Recompile Delphi RIO RTL/VCL?
Kryvich replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
@A.M. Hoornweg In newer Delphi versions you must put the $RTTI directive on each library unit. This is the main difference from XE. @Rollo62 I brought some statistics for my applications here: -
I would write it as localVar := ParameterValue; if localVar = None then localVar := DefaultValue; Presume that ParameterValue is assigned in most cases, then DefaultValue will not be accessed in most cases.
-
Recompile Delphi RIO RTL/VCL?
Kryvich replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
Perhaps this will help: -
Strange Behaviour of FillChar for Non Byte Array Arrays.
Kryvich replied to Ugochukwu Mmaduekwe's topic in RTL and Delphi Object Pascal
https://stackoverflow.com/questions/2113182/fillchar-but-for-integer-cardinal -
Using the Group Policy Editor it is possible to prevent users from accessing to Ctrl-Alt-Del options. https://ccm.net/faq/41738-how-to-prevent-users-from-accessing-the-task-manager