... how to get a repeated Array of that and have mouse clickable events to change the colour of a square on the initial grid.
There is a thread on this forumn that talks about using Arrays OR a TList to do the initial array. What would be the advantages of using a TList?
1. Store the information of all the clickable regionsPlease take a look on my source that not need anything what you wrote but works individual for each shape.
2. Check if the mouse click any of the regions
The information you need to store is the X1, Y1, X2, Y2 of the clickable position. Alternatively you can store X, Y, W, H. You may want to consider to use TRect:
https://lazarus-ccr.sourceforge.io/docs/rtl/types/trect.html (https://lazarus-ccr.sourceforge.io/docs/rtl/types/trect.html)
For checking if mouse click on any of the region, you can use OnClick or OnMouseDown events. To read the mouse position you use CursorPos. But then you need to do the conversion make it relative to the client coordinates.
Thanks KodeZwerg and Handoko for replying.You are welcome. :-*
now make a copy of that array 3 times across and 3 times down
You can modify "GenerateShapes" to have arguments like TShapes/top/left etc to have as many blocks as you want from such an array.Was I not clear enough? Simple create more than one FShapes and modify "GenerateShapes"
OK, I see.Can you express yourself more understandable?
For some reason the 1st row is missing.
Sorry.Ohhh :-[ Now I see... dunno... I am too tired right now to hunt down error, somewhere I made a small mistake but can not locate :'(
I did a screen shot to explain what I mean.
.. that the 1st row is missing (only 4 squares and not 5)
The difference in squares occurs at the very start (row1), so it must be some sort of initialization qwerk.Might be, might be not :P
Yes I will try that. I looked at KodeZwerg's code but could not find a fault.My error was, that I used your initial code which contained an error >:D
As ALWAYS, Thanks for helping out KodeZwerg.As always, you are welcome. ;)
Thanks KodeZwerg for the update and the new procedure with the additional 2 arguements (AOwner and AParent)AOwner = Self // in that case, TForm1 will be automagical used and is responsable to free my stuff
I added the modified GenerateBlocks procedure to replace other one without the arguements
private
//procedure GenerateBlocks;
procedure GenerateBlocks(const AOwner: TComponent; const AParent: TWinControl);
procedure ShapeEvent(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X , Y: Integer);
public
but in
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
FBlockRow := 4;
FBlockCol := 4;
FBlocksRow := 5;
FBlocksCol := 5;
FShapeWidth := 40;
FShapeHeight := 40;
FSpacing := 5;
FBlocks := nil;
Self.Width := (FBlockCol * FShapeWidth) * FBlocksCol + (FSpacing * 4);
Self.Height := (FBlockRow * FShapeHeight) * FBlocksRow + (FSpacing * 4);
GenerateBlocks(TForm1, TScrollBox1);
end;
what do I put here: GenerateBlocks(TForm1, which windowed control?);
I thought TWinControl was the scrollbox1 that I wanted the squares to be on, but comes up with error.
I am a bit confused about what to put in GenerateBlocks(TForm1, "????????);
Help say: TWinControl Implements a windowed control which can contain other child controls.
Thanks in Advance.
GenerateBlocks(TForm1, TScrollBox1);Both is wrong!
Now how to make a synchronised mouse click event in TForm1.ShapeEvent ?I show you one way of how to solve in attachment.
(i - (FBlockRow * FBlockCol) = LTag))that was a relict, outdated and i missed to remove.
Wow KodeZwerg. That's so cool.I am happy to help. O:-)
Thanks for adding the explanations.XOXOXO
Still can't believe that you achieved what I thought was impossible to achieve. I hard coded mine in VB6, but looks like Lazarus does arrays better. I liked how you put in hints in the previous code to look for patterns.Hardcoded = wrong coded >:D 8-)
When you code do you use any tools? I was thinking of using a snippets library program, to store bits and pieces of code.The only tool I use is what the IDE offers me, from time to time a calculator if I am too sleepy to do it in my head.
I don’t know if this will be helpful or not but I’d like to pass along some advice that was given to me back when I had some frames with a lot of shapes in them....Than I would rather do like Handoko telled, switching to a paintbox or image and instead of shapes, draw rectangles, get x/y location to know which "shape" was clicked on to maybe repeat that action for others.
You might eventually want to draw your shapes in a paintbox rather than using separate shape objects. When using paintbox Click Events determine which area in paintbox click occurred in simulating clicking on a shape.
If you ever have any difficulty with slowness like I did... 8)
Ah I see not "controls(i) but Components "Lol, I literal used that method all the time and just by now you asking me what Pred() (https://www.freepascal.org/docs-html/rtl/system/pred.html) means? :o
What does Pred mean? Hovering over Pred says Type LongInt so does that change type from longInt to integer?
Pred returns the element that precedes the element that was passed to it.
What about border ON/OFF boolean toggle?In GenerateBlocks you can update the Pen.Color to:
Here it is 1.30 AM so time to go to sleep. Getting tired now, as I returned to work (yesterday). See you for now. Thanks for the updates and explanations KodeZwerg.Have a good rest and whenever you are curious about updates, just ask :P