Jump to content

brk303

Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. I'm considering the following implementation for handling anonymous methods: TSomeClass = class fAnonymousMethods: integer; procedure Destroy; override; procedure TSomeClass .Destroy; var i: integer; begin repeat AtomicExchange(i, fAnonymousMethods); if i > 0 then Sleep(10); until i = 0; inherited; end; And, predictably in the anonymous method: AtomicIncrement(fAnonymousMethods); try // perform actual task finally AtomicDecrement(fAnonymousMethods); end; In my particular use case, network communication, there may be multiple anonymous threads sending queued up data in the background. The desired behaviour on shutdown is to complete sending whatever data may be queued up, which realistically takes a fraction of a second. So, if I use a simple integer counter, as in the code above, and wait a bit, that should solve the problem, right ? I don't see any flaws in this approach, other than it perhaps being a somewhat dirty shortcut, but is that really a problem, what do you guys think ?
  2. Hello everyone, I would like to display a user friendly string describing duration. So that it would produce strings along the line of : "33 milliseconds" "15 seconds" "1 minute and 5 seconds" "1 hour and 3 minutes" "1 day and 6 hours and 15 minutes" Or something similar. EDIT: Also ,notice that it would not say "10 days and 32 seconds", nor "2 months and 12 minutes" because that's not how people describe time. IOW, if you get into hours, the milliseconds don't matter any more, if you get into days, the seconds don't matter, if you get into months, the minutes don't matter, and so on. I could code it myself, but I wonder if there is already an implementation somewhere that I am not aware of. Thanks for your time.
  3. Thanks for the response. Would it be a good idea to have one port/connection for async communication and another one for sync ?
  4. I'm using a socket based async communication, but now also need ability to send blocking/synchronous request/reply. Basically, it needs to wait for result, and I'm wondering, what are ways to implement waiting. Communication is multithreaded and there might be various other messages going both ways while waiting for result. The only idea I have is to uniquely identify requests with say a random generated GUID, and pass the GUID back in response, so that client identifies the matching response. This must not be such a rare problem, and I wonder if there is some kind of standard solution for this? Or any other ideas how to go about?
  5. So if anyone is interested in the future, what I did to solve the problem was: In constructor of Form and Datamodule that I want to use at design time, I added the following: constructor TdmXXX.Create(AOwner: TComponent); begin inherited; if (csDesigning in ComponentState) then if not InitInheritedComponent(Self, TDataModule) then raise EResNotFound.CreateResFmt(@SResNotFound, [ClassName]); end; constructor TdmModelEdit.Create(AOwner: TComponent); begin inherited; if (csDesigning in ComponentState) then if not InitInheritedComponent(Self, TDataModule) then raise EResNotFound.CreateResFmt(@SResNotFound, [ClassName]); end; So this is the opposite of what happens in TCustomForm.Create.
  6. Yes, I have a standalone project with same code, that I can debug easier, and everything is correct there, so order of construction, etc is all fine. Since the code is same, the difference must be in VCL behavior at design time, and it seems what I wrote in previous post is the problem. Delphi does not load .dfm resource for forms created at design time. I was not aware of this, and it sounds severely limiting.
  7. I made new package with simple TComponent that creates a form, to debug it (since my real project is too big). It seems the problem is here: constructor TCustomForm.Create(AOwner: TComponent); begin .... InitializeNewForm; if (ClassType <> TForm) and not (csDesigning in ComponentState) then begin Include(FFormState, fsCreating); try DisableAlign; if not InitInheritedComponent(Self, TForm) then raise EResNotFound.CreateFmt(SResNotFound, [ClassName]); ... end; So if a TForm descendant is in csDesigning then InitInheritedComponent is not called and thus .dfm resouce is not loaded, so component name will stay blank, and all components in dfm will not be created. Not quite sure what to do now, one of components contains significant amount if data stored in dfm, so I can't just create it in code.
  8. Yes, but Form is a custom component editor, like say a DBConnection wizard, so it's not the kind you inherit in the project.
  9. I have a design time package which has a form linked to a datamodule. The same code is used for a standalone app, in which everything works fine, but in design time package the links between forms/datamodules are not restored. I have used RegisterFindGlobalComponentProc to hook in my function that does this: if AnsiSameText(Name, 'dmxxx) then Result := dmxxx This fixes the links from form to dmxxx, but I then found the dmxxx has name = '' and ComponentCount = 0, there should be 3 components on datamodule. All of this runs fine in standalone app outside IDE. Does anyone know what is different with component name/linking/restoring in IDE compared to standalone ?
×