Jump to content

Ian Branch

Members
  • Content Count

    1432
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Ian Branch

  1. Ian Branch

    TProcessList issue.

    Hi Team, D11.3.1. I have the following function I am trying to get to work.. function GetApplicationInstances(const FileName: string): TArray<string>; var ProcessList: TProcessList; Process: TProcess; i: Integer; begin Result := TArray<string>.Create; ProcessList := TProcessList.Create; try for i := 0 to ProcessList.Count - 1 do begin Process := ProcessList[i]; if Process.FileName = FileName then begin Result.Add(Process.UserName); end; end; finally ProcessList.Free; end; end; I have bothe System.SysUtils and System.Diagnostics in my Uses clause but I am still gettin an 'undeclared identifier' for TProcessList and TProcess. What have I missed please? Regards & TIA, Ian
  2. Ian Branch

    TProcessList issue.

    Solved. I added the count to the function. function GetApplicationInstances(const FileName: string; out Count: Integer): TArray<string>; var ProcessEntry: TProcessEntry32; Snapshot: THandle; ProcessList: TList<string>; begin ProcessList := TList<string>.Create; try Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if Snapshot <> INVALID_HANDLE_VALUE then begin ProcessEntry.dwSize := SizeOf(ProcessEntry); if Process32First(Snapshot, ProcessEntry) then begin repeat if (ProcessEntry.szExeFile = FileName) then // Replace with appropriate condition begin ProcessList.Add(ProcessEntry.szExeFile); end; until not Process32Next(Snapshot, ProcessEntry); end; CloseHandle(Snapshot); end; Result := ProcessList.ToArray; Count := ProcessList.Count; finally ProcessList.Free; end; end; Tks Guys. Regards, Ian
  3. Ian Branch

    TProcessList issue.

    OK. Moving on. Using Enums rather than TProcess. function GetApplicationInstances(const FileName: string): TArray<string>; var ProcessEntry : TProcessEntry32; Snapshot : THandle; ProcessList : TList<string>; begin ProcessList := TList<string>.Create(); try Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if Snapshot <> INVALID_HANDLE_VALUE then begin ProcessEntry.dwSize := SizeOf(ProcessEntry); if Process32First(Snapshot, ProcessEntry) then begin repeat if (ProcessEntry.szExeFile = FileName) then // Replace with appropriate condition begin ProcessList.Add(ProcessEntry.szExeFile); end; until not Process32Next(Snapshot, ProcessEntry); end; CloseHandle(Snapshot); end; Result := ProcessList.ToArray; finally ProcessList.Free; end; end; I have the following lines. var Instances: TArray<string>; Instances := GetApplicationInstances(sFileName); I can't see a way to get the number of elements in the TArray. I thought "for var i := 0 to TArray(Instances).Count do Memo1.Lines.Add(Instances);" would be a monty, but no. How please?
  4. Ian Branch

    TProcessList issue.

    Hi Team, I found that bit of code and thought it would do the trick. Oh well. What I am try to achieve is a delphi function that when given a full application path/name, return how many instances are in use and who is using them.
  5. Ian Branch

    TProcessList issue.

    Bummer. Any suggestions?
  6. Ian Branch

    Loop a Delay in a thread??

    Hi Team, I have ths construct: var GeneralThread := TThread.CreateAnonymousThread(procedure begin // tqServerSessions.Close; // try if TEDBEngineSessionManager(DBSWhoIsOn.Handle).TryLock(1) then begin TEDBEngineSessionManager(DBSWhoIsOn.Handle).Unlock; { Session is not locked and is safe for you to use } tqServerSessions.ExecSQL; end else // Delay for the specified amount of time TThread.Sleep(500); // except ... ... end; // tqServerSessions.Last; // ... ... end); How do I safely loop the Try-Else for x times, and then break out after x times?
  7. Ian Branch

    Loop a Delay in a thread??

    Tks Team. All sorted. Regards, Ian
  8. Ian Branch

    Strange one with zLib..

    Hi Team, D11.3.1. I have this compression routine. procedure CompressStream(SourceStream: TMemoryStream; DestStream: TMemoryStream); var ZStream : TCompressionStream; begin ZStream := TCompressionStream.Create(clDefault, DestStream); try ZStream.CopyFrom(SourceStream, SourceStream.Size); finally ZStream.Free; end; end; If I have this procedure in my main form it is happy. If I move it to my Function library, I get this.. Why should it be happy in the main form an not in the library? Yes, I have System.ZLib in the uses in both cases Thoughts/suggestions? Regards & TIA, Ian
  9. Ian Branch

    Strange one with zLib..

    Hi Lajos, Great call. I found that if I had the System.Zlib after the VCL.Graphics, all is fine. Before and I get the issue. Tks for the assist. Regards, Ian Edit: I didn't need VCL.Graphics in the library anyway. 😉
  10. Ian Branch

    Loop a Delay in a thread??

    Hi Remy, Yes, seriously. I don't really understand what goes on in Threads and therefore what you can and can't do. I am still learning about them. p2k, Tks. I will have a look. Tks to both of you. Regards, Ian
  11. Ian Branch

    Anything in a TMemoryStream??

    Hi Team, I am ostensibly sending a PDF file to a TMemoryStream. How do I test if the TMemoryStream has been 'loaded'? Regards & TIA, Ian
  12. Ian Branch

    Anything in a TMemoryStream??

    Ahhh. Yes. m.size. Shoulda thought of that. Tks. Ian
  13. Ian Branch

    I'm missing some nuance..

    Hi Team, I want to be able to make a generic function like this.. function SetDBSessionNames(const ComponentCount: Integer; const Components: TComponent; const sSessionName: string): boolean; begin // for var i := 0 to ComponentCount - 1 do begin // if (Components[i] is TEDBSession) then (Components[i] as TEDBSession).SessionName := sSessionName; // if (Components[i] is TEDBDatabase) then (Components[i] as TEDBDatabase).SessionName := sSessionName; // if (Components[i] is TnlhTable) then (Components[i] as TnlhTable).SessionName := sSessionName; // if (Components[i] is TnlhQuery) then (Components[i] as TnlhQuery).SessionName := sSessionName; // if (Components[i] is TnlhScript) then (Components[i] as TnlhScript).SessionName := sSessionName; // end; // end; That would be called like this.. // SetDBSessionNames(ComponentCount, Components, sSessionName); // The function is in a separate function library. Unfortunately it doesn't like "Components" in the if.... lines. 😞 I have obviously missed or misinterpreted some aspect. Some assistance/guidance would be appreciated. Regards & TIA, Ian
  14. Ian Branch

    I'm missing some nuance..

    Now we're getting fancy. 😉 But I like it. 🙂
  15. Ian Branch

    I'm missing some nuance..

    Hi Renate, That looks like a winner but this.. SetDBSessionNames(Self, sSessionName); Gives me this in this case.. In this case it is a Datamodule the function is being called from. Ian Edit: Solved - I made it an overload method and created one that use a TDataModule.
  16. Ian Branch

    I'm missing some nuance..

    Tks Keesver. That calms down the function itself, but now the calling function isn't happy What replaces Components in the calling function? SetDBSessionNames(ComponentCount, Components, sSessionName);
  17. Hi Team, I have a TListview that currently looks like this. I have tried to set the first column to Center justify but it keeps reverting to Left Justify. 😞 What I would like is for the first column to be center justified, and the second colmn's header to be center but the rest of column to be right. I would also like the Header font to be Bold as well, but there doesn't appear to be any 'Font' related property. 😞 Is this doable? If so, how please? Regards & TIA, Ian
  18. Hi p2k. Unfortunate. It offends my OCD. 😉 Ian
  19. Ian Branch

    Formatter doesn't work in a Unit??

    Is there a reason the formatter, CTRL-ALT-F, doesn't seem to work in a Unit without any Form? Or is it a Bug? Ian
  20. Ian Branch

    Formatter doesn't work in a Unit??

    Done..
  21. Ian Branch

    Formatter doesn't work in a Unit??

    Yup. Confirmed. Remove the comment on line 22 and the Formatter works on mine as well. In fact, if you have a comment on the end of any of the declarations, the Formatter fails. Whether it is a '//' or a '{ }' style comment. A strange thing. Thomas, You want a bug report? [edit] Bug Report submitted. Oooops! It went in as a feature request rather than a bug report. 😞 My Bad. Ian
  22. Ian Branch

    Formatter doesn't work in a Unit??

    😞 It works for me on all other units except for this one. 😞 OK. Thanks for your time. It is only a small one so no biggie to keep it formatted manually. Thansk to all for your input & support. Regards, Ian
  23. Ian Branch

    Formatter doesn't work in a Unit??

    Agreed, but it still has its quirks. 😉
  24. Ian Branch

    Formatter doesn't work in a Unit??

    Tks.
  25. Ian Branch

    Formatter doesn't work in a Unit??

    How would one identify a 'strabge character' out of the multitude?
×