Recent

Recent Posts

Pages: 1 ... 8 9 [10]
91
LCL / Re: Flickering issue when moving CheckboxList item
« Last post by KodeZwerg on March 31, 2023, 01:30:07 pm »
No flicker here either (Win 11, Laz/main (32bit) FPC 3.2.2).

Alternatively you could try a TListview with activated checkboxes (ListView1.Checkboxes := true); query the checked states from the corresponding TListItem property.

See attached demo (tested to work on Win, Linux/gtk2. It does not work on cocoa but there the customdrawn Checklistbox does not work either).
You forgot about the issue that he got so I've upgraded a little.
Set property DragMode for ListView1 to dmAutomatic
create OnDragDrop event with something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1DragDrop(Sender , Source: TObject; X , Y: Integer);
  2. var
  3.   MyItem : TListItem;
  4. begin
  5.   if Source = ListView1 then
  6.     with Source as TListView do
  7.       begin
  8.         if (GetItemAt(X,Y) <> nil) then
  9.           begin
  10.             MyItem := Items.Insert(GetItemAt(X,Y).Index);
  11.             MyItem.Assign(Selected);
  12.             Selected.Delete;
  13.           end;
  14.       end;
  15. end;
create OnDragOver event with something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1DragOver(Sender , Source: TObject; X , Y: Integer;
  2.   State: TDragState; var Accept: Boolean);
  3. begin
  4.   If Source = ListView1 then
  5.     Accept := True
  6.     else
  7.     Accept := False;
  8. end;

But I am unsure about how to display the content while you are dragging...
92
Beginners / Re: Variables as indexes of arrays
« Last post by Nitorami on March 31, 2023, 01:26:18 pm »
I mean all the settings you find under Options/Compiler. Maybe just make screenprints of tabs Syntax, Generated Code and Processor. Or post your fp.cfg file.
93
Beginners / Re: Variables as indexes of arrays
« Last post by JMarques on March 31, 2023, 01:13:39 pm »
I use the textmode IDE at version 1.0.12 with FPC 3.2.0, and also have 3.2.3 installed. Windowns 10. I tested your version and KodeZwerg's compact version and always get the expected output, regardless which compiler settings I tried, with 3.2.0 as well as 3.2.3. I would be really surprised if that was an FPC bug. Could you please specify your compiler settings i.e. target processor, optimisation etc.

Thank you the attention to my problem. The target processor is Win32 for i386. The compiler mode is set to Free Pascal dialect. I will be happy to give more information as needed provided you inform where to look at. Thanks again!
94
General / Re: How to access and set properties of Labels dynamically
« Last post by GetMem on March 31, 2023, 12:54:16 pm »
@wp
Quote
No, there is no circular unit reference when both units are listed under implementation
IIRC one of the unit can be in the interface section if the other one is in the implementation section.

I would pass Form1 to Form2's constructor, then store the reference in a private variable. Also subscribing to an event(as in your demo) is a nice solution.
95
General / Re: How to access and set properties of Labels dynamically
« Last post by KodeZwerg on March 31, 2023, 12:52:55 pm »
Also what is this Pred() I could not find it anywhere.
Pred gives back the Value - 1.
Therefore, unless you have a very simple project you should always avoid such a situation.
I second that, to me it is very bad code design as it may lead to future bugs.
96
General / Re: How to access and set properties of Labels dynamically
« Last post by wp on March 31, 2023, 12:45:00 pm »
No, there is no circular unit reference when both units are listed under implementation:
Code: Pascal  [Select][+][-]
  1. // Unit 1
  2. unit Unit1;
  3. interface
  4. ...
  5. implementation
  6. uses
  7.   Unit2;
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. begin
  10.   Form2.Show;
  11. end;
  12. end.
  13.  
  14. -------------------------------------------------------
  15.  
  16. // Unit 2
  17. unit Unit2;
  18. interface
  19. ...
  20. implementation
  21. uses
  22.   Unit1;
  23. ...
  24. procedure TForm2.Button1Click(Sender: TObject);
  25. var
  26.     i: integer;
  27. begin
  28.     i := Random(5) + 1;
  29.     Form1.LabelsArray[i].Caption := IntToStr(i);
  30. end;
  31. end.
  32.  

BUT: When the project gets bigger and bigger and more and more units are added the interdependence of the units becomes very complicated and there is a chance that such a solution will not compile any more. Also, you cannot test the project units independently - you always need Form1 if you want to test Form2 (and if Form1 uses other forms and units you will also need those - a huge mess!). Another issue is that unit2 compiles only when the instance of TForm1 is really named "Form1". Therefore, unless you have a very simple project you should always avoid such a situation.
97
General / Re: How to access and set properties of Labels dynamically
« Last post by KodeZwerg on March 31, 2023, 12:44:37 pm »
So I broke the idea down a bit to try and figure out what is going on, with this little bit of code it is also only listing components from Form2.
Code: Pascal  [Select][+][-]
  1.    for i := 0 to ComponentCount-1 do // <<<<< ERROR, you use componentcount for current form and not the one that you searched
  2.    Memo2.Lines.Add(Components[i].Name); // <<<<< ERROR, you use componentcount for current form and not the one that you searched
  3.  
So if you copy and paste, please do it correct  :-*
98
LCL / Re: Flickering issue when moving CheckboxList item
« Last post by paweld on March 31, 2023, 12:41:56 pm »
Draw only if indexes change:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.   c1, c2: Boolean;
  4. begin
  5.   if ssleft in shift then
  6.   begin
  7.     move_lay_son := CheckListBox1.ItemIndex;
  8.     if move_lay_son = move_lay_ilk then
  9.       exit;
  10.     c1 := CheckListBox1.Checked[move_lay_ilk];
  11.     c2 := CheckListBox1.Checked[move_lay_son];
  12.     CheckListBox1.Exchange(move_lay_ilk, move_lay_son);
  13.     CheckListBox1.Checked[move_lay_ilk] := c2;
  14.     CheckListBox1.Checked[move_lay_son] := c1;
  15.     move_lay_ilk := move_lay_son;
  16.   end;
  17. end;          
99
General / Re: How to access and set properties of Labels dynamically
« Last post by KodeZwerg on March 31, 2023, 12:39:21 pm »
I tried it but it only lists the components on Form2
I have no Idea about your projects source details so I attached a demo again that has on form2 a button to random change a "target/666" label from form1 or list everything that form1 has.
100
General / Re: How to access and set properties of Labels dynamically
« Last post by KodeZwerg on March 31, 2023, 12:30:48 pm »
and have no problems.
I do have a problem with your way.
Quote
Unit2.pas(8,9) Error: Circular unit reference between Unit2 and Unit1
Pages: 1 ... 8 9 [10]

TinyPortal © 2005-2018