-
Content Count
3323 -
Joined
-
Last visited
-
Days Won
110
Everything posted by Lars Fosdal
-
Beginner-Question: Server Prog, BackgroundWorker, unknown thread
Lars Fosdal replied to t2000's topic in OmniThreadLibrary
@Primož Gabrijelčič From the wishful thinking department: I'd love to see OTL evolve to support Linux/MacOS, iOS and Android. Hence, I'd love to see solutions that do NOT use Windows messaging - or at least hide it inside the notification implementation. -
VSoft.Awaitable - async/await for Delphi
Lars Fosdal replied to Vincent Parrett's topic in I made this
Is there a way to use it with "plugin" handlers instead on anonymous procedures? There are so many pitfalls with captures. -
Is Class with 2 'nested' constructors bad design?
Lars Fosdal replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
An alternative is to create completely independent classes, and use an interface to define the methods that you want to be general across the classes. -
Is Class with 2 'nested' constructors bad design?
Lars Fosdal replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
It requires some practice to wrap your head around encapsulation (pun intended) and thinking about how to make your code general or generic, if you like. A common base class mostly makes sense if you want to be able to ignore how it is used later, i.e. rely on polymorphism, and when you have a certain degree of reuse of code. Specific: Instance := TClassType.Create, then provide params -- Ideally, this would be the one place where you do something specific for the type when using it. General. Instance.LoadFiles; General: Instance.Compare; General: Output := Instance.CreateOutput; General: Render Output As you expand your hierarchy, you add properties and features only on the level where you need them. type TCompare = class procedure LoadFiles; virtual; procedure Compare; virtual; property File1: string; property File2: string; end; TCompare2Way = class(TCompare) procedure Compare; override; property Merge: Boolean; end; TCompare3Way = class(TCompare2Way) procedure LoadFiles; override; procedure CompareLeft; procedure CompareRight; procedure Compare; override; property File3: string; end; -
Do you use MadExcept or Eurekalog or similar? There might be hints in the nature of the callstacks.
-
Just to rule out any db access issues - have you tried logging into the database with the same user credential and connection settings as your ODBC connection uses and running the query manually?
-
Read in multiple lines and display them in a TMemo object
Lars Fosdal replied to stephanos's topic in General Help
begin Memo1.Lines.LoadFromFile('Test.txt'); // loads the entire file as is into the memo It is a bit unclear what you want to do per line, and if it can be automated or not? Do you have a collection of files that you want to merge into the Memo ? var Filename: string; FileContent: TStringList; begin FileContent := TStringList.Create; try for FileName in ListOfFileNames do begin FileContent.LoadFromFile(FileName); // Process it in FileContent here Memo1.Lines.AddStrings(FileContent); end; finally FileContent.Free; end; end; -
Users are a fickle bunch. Only devs are worse 😛
-
It would actually be nice to have something MDI like - but without the container. It would need multi-display support. The main window could be a narrow up top thing, or a sidebar thing.
-
Agree on the Joel thing - but the argument still stands with regards to MDI. Its demise has been plotted for at least two decades.
-
@Anders Melander: I may have been tooting the MS party line on MDI, without having read an actual deprecation statement, https://docs.microsoft.com/en-us/windows/win32/winmsg/multiple-document-interface "[Many new and intermediate users find it difficult to learn to use MDI applications. Therefore, you should consider other models for your user interface. However, you can use MDI for applications which do not easily fit into an existing model.]" However, this thread by Joel Spolsky from 2002 (!) accentuates how long ago MS started pushing that party line... https://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixpost=2748 Basic functionality seems to be there, even with Per Monitor V2 - but I only gave it a cursory glance. I think I was on 1809 the last time I checked and at the time it was definitively borked. Currently on 1909.
-
The last time I checked, I got transparent client areas and border areas.
-
MDI has been deprecated for years and is severely broken under Windows 10. Seems that a lot of messages no longer are sent or passed down to children.
-
Does the DLL itself try to load a second DLL which cannot be found or is the wrong bit-ness?
-
Do you get error 193 in your 64-bit application? Is the DLL 64-bit?
-
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
Unless you need multi-pass processing, or you have logic for conditional processing further down. -
what is the possibility of having a rest/soap webapi in Delphi 2007
Lars Fosdal replied to Ugochukwu Mmaduekwe's topic in Network, Cloud and Web
I'd go for the C# approach instead of fiddling with an ancient Delphi. -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
Absolutely. The Law of Demeter is something I usually follow quite strictly. However, in the above example - Session.Progress.Truck.Required ( & alike), Session has already been validated and Progress is an object where all the fields are always populated. I actually did make this structure instead of having a buttload of local variables. I have to figure out if a value has been given, and if it is given, it is valid, and if not - if it is a required value, and so forth, and some login types may need only some of the parameters. -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
A "modern" way of handing conditions is to do early exit on condition fail. In the above case it is pointless, but for more complex sequences it can make sense. Here is an example from a piece of JsonRPC handling code I wrote. In this case I don't do exits - since there is stuff that happens after the validation. Imagine this code if I had used nested if/then... // Handle login progress errors if Result and Session.Progress.Device.Required then begin if Session.Progress.Device.FailAsError then Response.SetError(Session.Progress.Device); Response.SetHint(Session.Progress.Device.Message); Response.SelectNextStep(S01_Login); Result := False; end; if Result and Session.Progress.User.Required then begin if Session.Progress.User.FailAsError then Response.SetError(Session.Progress.User); Response.SetHint(Session.Progress.User.Message); Response.SelectNextStep(S02_SelectUser); Result := False; end; if Result and Session.Progress.Mission.Required then begin if Session.Progress.Mission.FailAsError then Response.SetError(Session.Progress.Mission); Response.SetHint(Session.Progress.Mission.Message); Response.SelectNextStep(S03_SelectMission); Result := False; end; if Result and Session.Progress.Truck.Required then begin if Session.Progress.Truck.FailAsError then Response.SetError(Session.Progress.Truck); Response.SetHint(Session.Progress.Truck.Message); Response.SelectNextStep(TPGStep.S04_SelectVehicle); Result := False; end; if Result and Session.Progress.Area.Required then begin if Session.Progress.Area.FailAsError then Response.SetError(Session.Progress.Area); Response.SetHint(Session.Progress.Area.Message); Response.SelectNextStep(TPGStep.S05_SelectArea); Result := False; end; -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
If the same logic is used in multiple places, that shouts for generalization. function UserCanDeleteDocument(const aUser: TUser; const aDoc: TDoc): boolean; begin // can delete if Result := (aUser.Username = aDoc.Owner) // aUser owns ADoc or aUser.Administrator // or aUser has admin rights end; begin if UserCanDeleteDocument(aUser, aDoc) then begin // do the deletion end else ShowMessage('You are not allowed to delete this document'); end; -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
My argument comes from the goal of reducing code clutter and sanitizing conditions to be easy to read. Original code if aUser.Username<>aDocument.Owner then begin // If user is not an administrator if aUser.Administrator=false then begin showmessage('You are not allowed to delete this document'); exit; end; end; A boolean is by definition either true or false. An if condition takes a boolean argument, and if the argument is true, the following statement is executed. I don't need to check if BoolVar = true or BoolVar = false - only checking BoolVar or not BoolVar is enough. To have readable code, avoiding negations is a good thing, hence I would probably write the above something like this if (aUser.Username = aDocument.Owner) or aUser.Administrator then begin // do the deletion end else ShowMessage('You are not allowed to delete this document'); Naturally, there is no single right way of doing conditions - but explicitly comparing a boolean variable to a boolean value is unnecessary. -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
I have to admit that I cringe whenever I see a boolean compared to true or false. -
Boolean evaluation
Lars Fosdal replied to Ole Ekerhovd's topic in Algorithms, Data Structures and Class Design
Does the behavior change if you write If not aUser.Administrator then? -
Delphi Rio IDE hangs again and again
Lars Fosdal replied to microtronx's topic in Delphi IDE and APIs
We are still on the TMS Component Pack 9.0.3, but not using any of the data-aware components. -
Delphi Rio IDE hangs again and again
Lars Fosdal replied to microtronx's topic in Delphi IDE and APIs
Anyways - this is just guesswork. You'll have to turn every stone to solve this.