Recent

Recent Posts

Pages: 1 [2] 3 4 ... 10
11
General / Re: CheckListBox - Detect checkbox click
« Last post by gii on October 23, 2019, 10:52:51 pm »
The OnClickCheck event does not detect text clicks.
12
General / Re: CheckListBox - Detect checkbox click
« Last post by wp on October 23, 2019, 10:40:33 pm »
Don't do it yourself. Use the OnClickCheck event instead of OnMouseDown.
13
General / CheckListBox - Detect checkbox click
« Last post by gii on October 23, 2019, 10:20:06 pm »
I have a CheckListBox and in the OnMouseDown event I need to know if the user clicked on the text or Checkbox.

I currently use the following code:

Code: Pascal  [Select]
  1. procedure TForm1.CheckListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.     ARect : TRect;
  5.     AIndex : Integer;
  6. begin
  7.   AIndex := CheckListBox1.GetIndexAtXY( X, Y );
  8.  
  9.   if AIndex >= 0 then
  10.   begin
  11.     ARect := CheckListBox1.ItemRect( AIndex );
  12.     ARect.Left := ARect.Left + TWSCustomCheckListBoxClass(CheckListBox1.WidgetSetClass).GetCheckWidth(CheckListBox1);
  13.  
  14.     if PtInRect( ARect, Point( x, y ) ) = False then
  15.       Caption := 'Checkbox'
  16.     else
  17.       Caption := 'Text';
  18.   end;
  19. end;
  20.  

But the code:

Code: Pascal  [Select]
  1. TWSCustomCheckListBoxClass(CheckListBox1.WidgetSetClass).GetCheckWidth(CheckListBox1)
  2.  

Always returns zero.

This code was taken from the CheckLst.pas > TCustomCheckListBox.GetCheckWidth unit.

Code: Pascal  [Select]
  1. function TCustomCheckListBox.GetCheckWidth: Integer;
  2. begin
  3.   if HandleAllocated then
  4.     Result := TWSCustomCheckListBoxClass(WidgetSetClass).GetCheckWidth(Self)
  5.   else
  6.     Result := 0;
  7. end;  
  8.  

Can someone help me?
14
General / Re: SOLVED:need to use control name in instruction
« Last post by howardpc on October 23, 2019, 09:12:56 pm »
You can try some adaptation of this:
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Forms, Controls, Graphics, ComCtrls, StdCtrls, Classes;
  9.  
  10. type
  11.  
  12.   TForm1 = class(TForm)
  13.     Button1: TButton;
  14.     Edit1: TEdit;
  15.     Label1: TLabel;
  16.     PageControl1: TPageControl;
  17.     TabSheet1: TTabSheet;
  18.     TabSheet2: TTabSheet;
  19.     TestButton: TButton;
  20.     procedure TestButtonClick(Sender: TObject);
  21.   end;
  22.  
  23.   procedure SetControlColorsInTabsheet(aTabSheet: TTabSheet;
  24.             aColor, aFontColor: TColor; aControlClasses: array of const);
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. procedure SetControlColorsInTabsheet(aTabSheet: TTabSheet; aColor,
  32.              aFontColor: TColor; aControlClasses: array of const);
  33.  
  34.   function DesiredControlClass(aControlClass: TControlClass): Boolean;
  35.   var
  36.     vr: TVarRec;
  37.   begin
  38.     for vr in aControlClasses do
  39.       if (vr.VType = vtClass) and (vr.VClass = aControlClass) then
  40.         Exit(True);
  41.     Result := False;
  42.   end;
  43.  
  44. var
  45.   i: Integer;
  46. begin
  47.   with aTabSheet do
  48.     for i := 0 to ControlCount-1 do
  49.       if DesiredControlClass(TControlClass(Controls[i].ClassType)) then
  50.         begin
  51.           Controls[i].Color := aColor;
  52.           Controls[i].Font.Color := aFontColor;
  53.         end;
  54. end;
  55.  
  56. {$R *.lfm}
  57.  
  58. { TForm1 }
  59.  
  60. procedure TForm1.TestButtonClick(Sender: TObject);
  61. begin
  62.   SetControlColorsInTabsheet(TabSheet2, clBlue, clSilver, [TEdit, TButton, TLabel]);
  63. end;
  64.  
  65. end.
15
Windows / Re: Programming a driver for a virtual folder and virtual files?
« Last post by marcov on October 23, 2019, 09:08:08 pm »
Some of the interfaces named in the codeproject article are available in unit shlobj
16
General / Re: SOLVED:need to use control name in instruction
« Last post by xaver13 on October 23, 2019, 08:03:18 pm »
good, thank you! Now I am using
Code: Pascal  [Select]
  1.      for i := 0 to TabSheet2.ControlCount -1 do
  2.       if TabSheet2.Controls[i] is Tedit or TabSheet2.Controls[i] is TDBEdit or TabSheet2.Controls[i] is TLabel then begin
  3.         TabSheet2.Controls[i].Color := clBlack;
  4.         TabSheet2.Controls[i].Font.Color := clSilver;
  5.       end;
  6.  

But maybe should be nicer something as:  ;)
Code: Pascal  [Select]
  1. Type
  2.     blackControls = (TDBEdit, TEdit,TLabel)
  3. begin
  4.      for i := 0 to TabSheet2.ControlCount -1 do
  5.       begin
  6.       if TabSheet2.Controls[i] in blackControls do begin
  7.         TabSheet2.Controls[i].Color := clBlack;
  8.         TabSheet2.Controls[i].Font.Color := clSilver;
  9.       end;
  10. end;
  11.  

is it possible to use in there and how?
17
General / Re: SOLVED:need to use control name in instruction
« Last post by lucamar on October 23, 2019, 07:21:54 pm »
You can do it for any descendant of TControl since most of them inherit their Name, Color and Font from the base class:

Code: Pascal  [Select]
  1. for i := 0 to TabSheet2.ControlCount -1 do
  2. begin
  3.   if TabSheet2.Controls[i].Name = 'kolik' then begin
  4.     TabSheet2.Controls[i].Color := clBlack;
  5.     TabSheet2.Controls[i].Font.Color := clSilver;
  6.   end;
  7. end;

In that case you don't need to (and, indeed, shouldn't) hard-cast to the wanted class but use directly the TControl object returned by Controls "array" element getter.

That should cope with almost any control whether a descendant of TWinControl, like TEdit, or of TGraphicControl, like TSpeedButton and TColorButton.

HTH
18
Packages and Libraries / FPImageException with Lazmapviewer
« Last post by Bert_Plitt on October 23, 2019, 06:55:31 pm »
I downloaded and installed the packages from  lazarus-ccr-svn-r7167-components-lazmapviewer into Lazarus ver. 2.0.4, FPC ver. 3.0.4. (Windows 10)  I Opened, built, and ran the example project.  While experimenting with the example, I right clicked on the map to add a GPS point.  I entered a name and, as I expected, the point showed up on the map as a + sign and the name I entered.  Using the mouse to drag the map, the GPS point tracked the map movement.  But when the GPS point got to the left edge of the map view port, the program raised a "'FPImageException' exception: Invalid horizontal pixel index -7".  The same exceptions occur if the GPS point exceeds the top, bottom or right edge of the view port.  Does anyone know how to fix this?
19
Graphics / Re: Read 1 bit tiff file
« Last post by circular on October 23, 2019, 06:48:29 pm »
That's interesting. So if I understand correctly, that is an object file from LibTiff that is statically linked so that you wouldn't have LibTiff dependency on Windows?
20
Mac OS X / Re: Run error on binary compiled on Catalina after update to fpc trunk
« Last post by Thaddy on October 23, 2019, 06:09:07 pm »
It means there are errors in your code: trap 6 is usually a memory access violation. I do not have that error on Catalina
Your code is possibly wrong.

Show us a small example that reproduces it.
Trunk does not mean anything without a revision number, by the way... So add that too.
Pages: 1 [2] 3 4 ... 10