

JohnLM
Members-
Content Count
350 -
Joined
-
Last visited
Everything posted by JohnLM
-
Specs: Delphi XE7, VCL, Windows 7 - DBGrid and added a checkbox column to it I've searched around the web for ideas and howtos. Well, I came across a few resources and met with some success. I've even added/included an additional feature to allow user (that's me) to add edit checkbox via keyboard space. It works. https://www.thoughtco.com/place-a-checkbox-into-dbgrid-4077440 https://stackoverflow.com/questions/9019819/checkbox-in-a-dbgrid I copy/pasted the code from the second link, then I added the code to allow checkbox column updates via the keyboard space (spacebar) from the first link, and ported to the code from the second link. I hope that made sense. <-- My first "codesnippet" contribution to the community !! However, there appears to be one small problem. The checkbox column is showing the text: True or False, whichever is set to., and you can see the outline of the column box when that field is entered into. Complete source code is included below. Just add a (dbgrid, button, tfdmemtable, and datasource) to your forum, and be sure to double-click the event(s) for each of these Procedures in order to activate them. You can click the ch field or hit the spacebar to update the checkbox field. Is there any way I can resolve this artifact? unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs, Data.DB, FireDAC.Comp.Client, Vcl.Grids, Vcl.DBGrids, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.VCLUI.Wait, FireDAC.Comp.UI; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; eb1: TEdit; conn: TFDConnection; btnInsert: TButton; DBGrid1: TDBGrid; ds: TDataSource; mytable: TFDMemTable; procedure Button1Click(Sender: TObject); procedure btnInsertClick(Sender: TObject); procedure dbgrid1CellClick(Column: TColumn); procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); procedure DBGrid1ColEnter(Sender: TObject); procedure DBGrid1ColExit(Sender: TObject); procedure DBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormCreate(Sender: TObject); procedure DBGrid1KeyPress(Sender: TObject; var Key: Char); private { Private declarations } GridOriginalOptions : TDBGridOptions; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnInsertClick(Sender: TObject); begin myTable.FieldDefs.Clear; mytable.FieldDefs.Add('ch', ftBoolean, 0,false); // the checkbox 'ch' a boolean myTable.FieldDefs.Add('id', ftAutoInc, 0,False); myTable.FieldDefs.Add('name',ftString, 20,False); myTable.CreateDataSet; myTable.Append; myTable.FieldByName('name').AsString := 'delphi'; myTable.Post; mytable.Open; end; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const CtrlState: array[Boolean] of integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED) ; begin if (Column.Field.DataType=ftBoolean) then begin DBGrid1.Canvas.FillRect(Rect) ; if (VarIsNull(Column.Field.Value)) then DrawFrameControl(DBGrid1.Canvas.Handle,Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_INACTIVE) else DrawFrameControl(DBGrid1.Canvas.Handle,Rect, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]); end; end; procedure TForm1.DBGrid1ColEnter(Sender: TObject); begin if Self.DBGrid1.SelectedField.DataType = ftBoolean then begin Self.GridOriginalOptions := Self.DBGrid1.Options; Self.DBGrid1.Options := Self.DBGrid1.Options - [dgEditing]; end; end; procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ((Self.DBGrid1.SelectedField.DataType = ftBoolean) and (key = VK_SPACE)) then begin Self.DBGrid1.DataSource.DataSet.Edit; Self.DBGrid1.SelectedField.Value:= not Self.DBGrid1.SelectedField.AsBoolean; Self.DBGrid1.DataSource.DataSet.Post; end; end; // this portion of code snippet is my contribution to the community. I did not see this code anywhere. it does work. procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin if (key = ' ') then begin self.DBGrid1.DataSource.DataSet.Edit; self.DBGrid1.SelectedField.Value := not self.DBGrid1.Fields[0].AsBoolean; self.DBGrid1.DataSource.DataSet.Post; end; end; procedure TForm1.FormCreate(Sender: TObject); begin GridOriginalOptions := DBGrid1.Options end; procedure TForm1.DBGrid1ColExit(Sender: TObject); begin if Self.DBGrid1.SelectedField.DataType = ftBoolean then Self.DBGrid1.Options := Self.GridOriginalOptions; end; procedure TForm1.dbgrid1CellClick(Column: TColumn); begin if (Column.Field.DataType=ftBoolean) then begin Column.Grid.DataSource.DataSet.Edit; Column.Field.Value:= not Column.Field.AsBoolean; Column.Grid.DataSource.DataSet.Post; end; end; end.
- 4 replies
-
- delphi xe7
- vcl
- (and 4 more)
-
The artifact in the boolean checkbox column is now gone. Thank you @Uwe Raabe for the help, much appreciated.
- 4 replies
-
- delphi xe7
- vcl
- (and 4 more)
-
setting DefaultDrawing property to False does help, but the second part causes additional artifacts and also does not show the cursor. I did try adding it into the section you mentioned but it gave me artifacts or missing data, etc.. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const CtrlState: array[Boolean] of integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED) ; begin if (Column.Field.DataType=ftBoolean) then begin //dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); DBGrid1.Canvas.FillRect(Rect) ; if (VarIsNull(Column.Field.Value)) then //begin DrawFrameControl(DBGrid1.Canvas.Handle,Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_INACTIVE) //dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end else //begin DrawFrameControl(DBGrid1.Canvas.Handle,Rect, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]); //dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end; end; end;
- 4 replies
-
- delphi xe7
- vcl
- (and 4 more)
-
Specs: Delphi XE7, Windows 7 64bit laptop. There is a "rundll32.exe" that keeps running every day. Now, I know that this is used in various ways during regular Windows operations, like for instance, when you open the sound volumn applet (via taskbar icon) and select the speaker icon, the "rundll32" activates and runs services. The service is running a HDD file collection activity because my HDD light is on continuously. And after searching around the web for answers, I found many Delphi routines that end or kill a process by program name and process_id. I am using the PID to be more accurate. Then, I wrote an app to detect when this file or service runs and End or Kill its process via its PID, but the process does not end. I think I've tried all the methods that I found and still, this "rundll32.exe" file will not stop running. I am pretty sure that this is a backgroud (scheduled) task that can be turned off somewhere in "services.msc" but that method is not what I want to use in this case. This endeviour has stumped me and I want to figure it out in the route I am in now. Any advice or suggestions or code corrections on how to proceed would be greatly appreciated. function KillProcessTree(const PID: Cardinal): boolean; var hProc, hSnap, hChildProc : THandle; pe : TProcessEntry32; bCont : BOOL; begin Result := true; FillChar(pe, SizeOf(pe), #0); pe.dwSize := SizeOf(pe); hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnap <> INVALID_HANDLE_VALUE) then begin if (Process32First(hSnap, pe)) then begin hProc := OpenProcess(PROCESS_TERMINATE{PROCESS_ALL_ACCESS}, false, PID); if (hProc <> 0) then begin Result := Result and TerminateProcess(hProc, 1); WaitForSingleObject(hProc, INFINITE); CloseHandle(hProc); end; bCont := true; while bCont do begin if (pe.th32ParentProcessID = PID) then begin KillProcessTree(pe.th32ProcessID); hChildProc := OpenProcess(PROCESS_TERMINATE{PROCESS_ALL_ACCESS}, FALSE, pe.th32ProcessID); if (hChildProc <> 0) then begin Result := Result and TerminateProcess(hChildProc, 1); WaitForSingleObject(hChildProc, INFINITE); CloseHandle(hChildProc); end; end; bCont := Process32Next(hSnap, pe); end; end; CloseHandle(hSnap); end; end; and. . . function Killtask2(exefilename: string): integer; Const process_terminate = $0001; Var Continueloop: Bool; Fsnapshothandle: THandle; fprocessentry32: TProcessentry32; Begin Result := 0; Fsnapshothandle := CreateToolhelp32Snapshot (Th32cs_snapprocess, 0); FProcessEntry32.dwsize := Sizeof(FPROCESSENTRY32); Continueloop := Process32First (Fsnapshothandle, FPROCESSENTRY32); while integer (continueloop) <> 0 do begin if (Uppercase(Extractfilename (FProcessEntry32. szexefile)) = Uppercase(Exefilename)) or (Uppercase(FProcessEntry32. Szexefile) = Uppercase(Exefilename)) then Result := Integer(TerminateProcess(OpenProcess(Process_terminate, BOOL (0), FProcessEntry32. Th32processid), 0)); Continueloop := Process32Next(Fsnapshothandle, FPROCESSENTRY32); end; CloseHandle(Fsnapshothandle); End; and this one. . . function KillTask(ExeFileName: string): Integer; const PROCESS_TERMINATE = $0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin Result := 0; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then Result := Integer(TerminateProcess( OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0)); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end;
-
Success!! It is working. Serv LN Time in/out PID Action ------------- -- ----------- ---- ------ rundll32.exe 45 12:00:02 AM 6460 killed Now it is time to make some enhancements and add a custom running db list of items to keep track of that come up during the day and review for potential Action.
-
Thanks for the responses. Okay, I believe I have found out why my app was failing at closing the "rundll32.exe" (and other running processes). I did not run the app as Admin. I know a few processes that show up in Task Manager and come back again after ending those tasks. For instance, the "HeciServer.exe - Intel(R) Capability Licensing Service Interface" will not close. I know because it has the same ProcesID (PID) but if I run the app as Admin, it closes and relaunches again but with a new PID. In my app I have it so that it shows the PID for each app listed and slated for shutting down via one of the end process funtions I listed in my first post. But I have not tested it on the rundll32.exe yet. I have to wait until it decides to start. I'll know then if the app works for this particular file and report back about it later.
-
Is there a way to check is the "user Idle" (no interaction)
JohnLM replied to Tommi Prami's topic in Windows API
I played around with the routine from James Campbell's (Feb 6, 2020) answer from @Lars Fosdal's posted link, and posted again, below. https://stackoverflow.com/questions/2212823/how-to-detect-inactive-user Note: To make testing/debugging easier, I made this change: FormStyle=fsStayOnTop in the Object Inspector area so that I could better observe the app's behavior. And, while the app does work as expected, when I minimize the app and go into another running app or use keyboard/mouse activity outside the said app, it would continue to work--that is, in the timer section it would continue. I modified the code to: detect the app's active status and check if it is minimized. procedure TForm1.Timer1Timer(Sender: TObject); begin if (application.Active=true) and (WindowState = wsMinimized) then else if application.Active=true then begin Caption := Format('System IDLE last %d seconds', [SecondsIdle]) ; end; end; And now it seems to work as expected when it is minimized the counting in the timer event is ignored, and if the app is active in the foreground, the counting continues. -
I have this routine that lists all running processes in a listbox under Windows 7. However, it is not a complete list as I thought, because when I load up the Task Manager, it has more entries (when I select '[y] show processes from all users'). Here is a complete project listing showing two working methods to obtain the running processes into a listbox. The only limitations with these are that they show less entries than what the Task Manager shows. Question: How do I obtain that same listing in delphi that the Task Manager shows? TIA. unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls; type TForm1 = class(TForm) Panel1: TPanel; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; m1: TMemo; lb1: TListBox; btnGetProcesses1: TButton; Splitter1: TSplitter; btnPause: TButton; st1: TStaticText; btnGetProcesses2: TButton; procedure btnPauseClick(Sender: TObject); procedure btnGetProcesses2Click(Sender: TObject); procedure btnGetProcesses1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure GetProcesses_1; procedure GetProcesses_2; end; var Form1: TForm1; ts: tstrings; n: integer=0; // out counter for the listbox of items. implementation {$R *.dfm} uses tlHelp32; procedure tform1.GetProcesses_1; // #1 var handler: THandle; data: TProcessEntry32; PID: cardinal; function GetName: string; var i:byte; begin Result := ''; i := 0; while data.szExeFile[i] <> '' do begin Result := Result + data.szExeFile[i]; //PID := data.th32ProcessID; Inc(i); end; end; begin n:=0; ts:=tstringlist.Create; Data.dwSize := SizeOf(Data); form1.DoubleBuffered:=true; lb1.DoubleBuffered := true; lb1.Items.BeginUpdate; lb1.Items.Clear; lb1.Sorted:=true; handler := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); if Process32First(handler, data) then begin ts.Add(GetName()); //lb1.Items.Add({inttostr(data.th32ProcessID) + ': '+}GetName()); while Process32Next(handler, data) do begin ts.Add(GetName()); inc(n); //lb1.Items.Add({inttostr(data.th32ProcessID) + ': '+}GetName()); end; end else ShowMessage('Error'); lb1.Items.EndUpdate; lb1.Items.Assign(ts); st1.Caption := inttostr(n); ts.Free; end; procedure TForm1.btnGetProcesses1Click(Sender: TObject); begin GetProcesses_1; end; procedure tform1.getprocesses_2; // method #2, from https://www.vbforums.com/showthread.php?350779-Delphi-Getting-Running-processes-into-a-List-Box-and-Kill-Selected var MyHandle: THandle; Struct: TProcessEntry32; begin n:=0; try MyHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0); Struct.dwSize:=Sizeof(TProcessEntry32); if Process32First(MyHandle, Struct) then form1.lb1.Items.Add(Struct.szExeFile); while Process32Next(MyHandle, Struct) do begin form1.lb1.Items.Add(Struct.szExeFile); inc(n); end; except on exception do ShowMessage('Error showing process list'); end end; procedure TForm1.btnGetProcesses2Click(Sender: TObject); // method #2 begin n:=0; getprocesses_2; st1.Caption := inttostr(n); end; end.
- 3 replies
-
- delphi
- task manager
-
(and 3 more)
Tagged with:
-
How do I show a complete list of running processes?
JohnLM replied to JohnLM's topic in General Help
@Anders Melander and @Remy Lebeau - Thank you for the tips.- 3 replies
-
- delphi
- task manager
-
(and 3 more)
Tagged with:
-
D2007: Initialise byte array in const record
JohnLM replied to Nigel Thomas's topic in Algorithms, Data Structures and Class Design
This works for me in XE7. type FileSig = record Offset: Integer; text: string; arrSig: array of byte; arrStr: array of char; end; const sig1: FileSig = ( offset:10; text:'test'; arrsig:[65,66,67]; arrStr:['a','b','c'] ); var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin memo1.Lines.Add(sig1.Offset.ToString()); memo1.Lines.Add(sig1.text); memo1.Lines.Add( inttostr(sig1.arrSig[0]) ); memo1.Lines.Add('[' + ansistring(sig1.arrSig) + ']'); memo1.Lines.Add('[' + string(sig1.arrStr) +']'); end; Output Results: 10 test 65 [ABC] [abc] -
How do I find my NNTP server name so that I can use XannaNews?
JohnLM posted a topic in General Help
Hi, I am trying to find my (NNTP) server name so that I use setup and use with XanaNews. My provider is Optimum Internet here in the States. It has been years since I used a newsreader. My last reader was with Netscape in Windows 98. It was pretty easy to use back then. When you phone Optimum they mainly have automated choices, so that is not an option. I've tried CMD and entered "hostname" but that gives me my computer name. Also tried ipconfig /all but that returns a bunch of details that I do not understand. Is there another way to obtain it through software or else the internet? TIA. -
How do I find my NNTP server name so that I can use XannaNews?
JohnLM replied to JohnLM's topic in General Help
I did not know that. I had downloaded an old Delphi project and was reading the readme.txt it came with and saw a link to the usernet newsgroup "https://groups.google.com/g/comp.lang.pascal.delphi.misc" The topic of the post in the newgroup was from Tim Robert's, from April 17, 1997, related to an Delphi project by efg (Early F. Glynn) and I was trying to see what he wrote about. When I entered that address in Chrome, I could only scroll via "<" and ">" icons and it took me about 4 hours to get to the date range of 4/1997, but I did not find the April 17, 1997 post mentioned in the readme.txt file. And, after retiring for the day, I left the tab open there and shut down the laptop in sleep mode, and the next day, the date had gone back up to 2023. Although I was looking in the newsgroup for that particular topic, I want to continue searching other newsgroup topics, so I would like a newsreader that works. Many topics will probably be from the days of old, for stuff you can't find on the internet anymore these days because those sites closed down for instance. -
EMB has just put out a video discussing 12.1
-
@Lainkes - this is probably what you are after. Put the if/then code snippet (below) into the OnColEnter event of the DBGrid. And every time you enter that field that you set .FieldName='myfieldname' to, will highlight your button bold or non-bold. procedure TForm1.dbgrid1ColEnter(Sender: TObject); begin if db1.SelectedField.FieldName='myfieldname' then button1.Font.Style := [fsBold] else button1.Font.Style := []; end;
-
Resolved - regarding the .dcu files. Under the: options -> Environment Options -> Delphi Options -> Library -> Library Path: I added the "\WebView4Delphi-main\source\" folder After this update, the SimpleBrowser compiled and ran.
-
Your suggestion to change the 'Package output directory' worked. The components have been added successfully. Thanks. However, when I try to compile a few of your demos, they fail. It seems none of the .dcu files are being created and Delphi can't find them at compile time. below are from your SimpleBroswer demo. They are in the Uses section with red underlines. uWVBrowser, uWVWinControl, uWVWindowParent, uWVTypes, uWVConstants, uWVTypeLibrary, uWVLibFunctions, uWVLoader, uWVInterfaces, uWVCoreWebView2Args, uWVBrowserBase
-
Unfortunately, I am still getting the same error message stated in my first post above. I've also downloaded the latest version, which are dated 3/9/2024. Please note, each file that I Build, I am first double-clicking on it to select it. WebView4DelphiVCLRTL.bpl, when I right-click it, I select Build, when it finishes, I get Done. WebView4DelphiFMXRTL.bpl, when I right-click it, I select Build, when it finishes, I get Warnings. WebView4DelphiVCL_designtime.bpl when I right-click it, I select Build, when it finishes, I get Done. ** this is the file that will not complete when I right-click and select Install. I get the error message stated earlier. ** WebView4DelphiFMX_designtime.bpl when I right-click, I select Build, when it finishes, I get Warnings. ** this file also will not complete when I right-click and select Install. I get the error message stated earlier. **
-
Hi, I'm having trouble installing webview4delphi under Delphi XE7. I am receiving the following error: "The program can't start because WebView4DelphiVCLRTL.bpl is missing from your computer. Try reinstalling the program to fix this problem." But the file is showing in the listing below:
-
Oops, posted in the wrong topic. Will post in correct one shortly.
-
I was replying to @Clément.
-
okay, how about setting DoubBuffered:=true ? That is used to stop flicker in most controls and I've used this feature for many years, since Delphi 6. The following may work: form1.doublebuffered := true; toolbar1.doublebuffered := true; titlebarpanel1.doublebuffered := true; You can add that in the form's Create of Activate event. This should work.
-
1. add a timage to the form. 2. load the a picture via Object Inspector window (or load via code) 3. use the following code snippet in a button event or other area of your source code. note: if the image is large and you shrink it, it may animate with image distortions. form1.DoubleBuffered := true; (image1.picture.graphic as TGifImage).Animate := true; (image1.picture.graphic as TFifImage).AnimationSpeed := 150;
-
I was searching around bestbuy for a streaming device that I could hook up my phone to the device and connect it to my laptop. And after searching around I saw that there are other ways to stream using OBS software on the laptop and installing an app on the phone via an ipp address. Is there a way to do this with Delphi so I don't have to worry about installing someone's app and being on *their* server? I would rather do it the Delphi way if possible, TIA.
-
My main laptop hdd crashed, will not boot into win7, only in basic safe mode. The one i mentioned is the same exact model, and i restored an old backup to it from few yrs ago. But it does not have the wifi chip in it and i dont want to mess with it at this time.
-
I want to watch some youtube videos, but from my phone, streamed to my laptop, and maybe to my win10 tablet.