Working with Objects and how to make a form object move for an object

Lets say I have a objects that’s are all descendants of TWinControl and their are many descendants of TWinControl. I want to use the mouse for boundary controls much like to Move and Size before the user in run time. and have settings to optionally stop size.
So I create my own TWinControl descendant as a Form object on the form in run time and the user can move it around and Size it in the form as a movable/sizeable looking object on the form and looks like a shape for moving and sizing on the form as a screen object.
My object TMove offers a TWinControl link but call it a WinControllink.
When TMove is shown the other is not shown. When finished the move - TMove visible is removed and the override of TMove visible returns through the WinControllink the other object as visible and in the same place as TMove was.
Looks like one object to the user but in fact two objects.

Sounds like the movie ‘predictor’ nearly
Do you think it will work?
I need to set Auto Size to both objects
I have visible and boundaries access to both objects
When I take over the the mouse events what is the best direct windows call to move the objects location of my buddy object?

?

You likely want something like “buddyobject.SetBounds(…)”

The boundaries and communication through TWinControl just need the standard checks in place.
What’s the important one is the mouse move event and the message to send back to windows to move the object. The identifying the side to size the object’s bottom Right Conner/sides I can work out mouse position to the object but I do not have the message to send to windows directly so I remove delays and shacking movement on the canvas.

I think this might be strange in my TMove create containing a TWinControl I’m taking over for the move, and so the TWinControl disappears with TMove in its place - I move TMove on the form when TMove is destroyed the TWinControl appears in its place to simplify things.

I have come to this idea because I understand the purpose of TWinControl and that is what you cannot get out of books.

unit Move;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms;

type
  TCustMove = class(TCustomControl)
   protected
    FkeyControl: TWinControl;
    FXPos: Integer;
    FYPos: Integer;
  end;

  TMove = class(TCustMove)
   protected
    procedure Paint; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
   public
    constructor Create(AOwner: TComponent; TakeOverControl: TWinControl); Reintroduce;
    destructor Destroy; override;
  end;

implementation

{ TMove }

constructor TMove.Create(AOwner: TComponent; TakeOverControl: TWinControl);
begin
  inherited Create(AOwner);
  FkeyControl := TakeOverControl;
  SetBounds(FkeyControl.Left -7, FkeyControl.Top - 7, FkeyControl.Width + 7,
            FkeyControl.Height + 7);
  If Width < 15 then Width := 15;
  If Height < 15 then Height := 15;
  FkeyControl.Visible := False;
  FXPos := 0;
  FYPos := 0;
end;

destructor TMove.Destroy;
begin
  FkeyControl.Visible := True;
  FkeyControl.SetBounds(FkeyControl.Left, FkeyControl.Top, FkeyControl.Width,
                        FkeyControl.Height);
  inherited;
end;

procedure TMove.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  FXPos := 0;
  FYPos := 0;
  if (Button = mbLeft) then
   Begin
    If (Y > Height -5) then FYPos := Y;
    If (X > Width -5) then FXPos := X;
    If (Y < 5) then FYPos := Y;
    If (X < 5) then FXPos := X;
   End;
end;

procedure TMove.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  //
end;

procedure TMove.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  //
end;

procedure TMove.Paint;
Var aRect, ObjectRect: TRect;

Procedure FillRect(var ARect: TRect);
begin
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
end;

begin
  inherited;
  ObjectRect := GetClientRect;
  Canvas.Brush.Color := clWhite;
  ObjectRect.Left := ObjectRect.Left + 3;
  ObjectRect.Right := ObjectRect.Right - 3;
  ObjectRect.Top := ObjectRect.Top + 3;
  ObjectRect.Bottom := ObjectRect.Bottom - 3;
  Canvas.FillRect(ObjectRect);
  Canvas.DrawFocusRect(ObjectRect);
  Canvas.Brush.Color := clAqua;
  aRect := GetClientRect;
  aRect.Right := aRect.Left + 7;
  aRect.Bottom := aRect.Top + 7;
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
  aRect.Left := aRect.Right - 7;
  aRect.Bottom := aRect.Top + 7;
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
  aRect.Left := aRect.Right - 7;
  aRect.Top := aRect.Bottom - 7;
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
  aRect.Right := aRect.Left + 7;
  aRect.Top := aRect.Bottom - 7;
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
  aRect.Right := aRect.Left + 7;
  aRect.Top := aRect.Bottom - 7;
  Canvas.FillRect(aRect);
  aRect := GetClientRect;
  aRect.Right := aRect.Left + 7;
  aRect.Top := aRect.Bottom - 7;
  Canvas.FillRect(aRect);
  aRect.Left := (GetClientRect.Left + GetClientRect.Right) Div 2 - 4;
  aRect.Right := (GetClientRect.Left + GetClientRect.Right) Div 2 + 3;
  aRect.Bottom := GetClientRect.Top + 7;
  aRect.Top := GetClientRect.Top;
  Canvas.FillRect(aRect);
  aRect.Left := (GetClientRect.Left + GetClientRect.Right) Div 2 - 4;
  aRect.Right := (GetClientRect.Left + GetClientRect.Right) Div 2 + 3;
  aRect.Bottom := GetClientRect.Bottom;
  aRect.Top := GetClientRect.Bottom - 7;
  Canvas.FillRect(aRect);
End;

end.

This is a ruff out of my code

with all the screen curser display options
https://docwiki.embarcadero.com/RADStudio/Athens/en/Mouse_Cursor_Constants

how can I record a curser option
example I bring up a move on the curser and then I press the mouse button and want to lock the curser to continue with the same display
I’m finding when I move my object some of the painting is not painting because I believe using left and top instead of a object message to windows is to great a delay.

I’m not 100% understanding what you’re trying to achieve but have you looked at the BeginDrag/EndDrag methods?

https://docwiki.embarcadero.com/Libraries/en/Vcl.Controls.TControl.BeginDrag

It might be that it would be easier to use these rather than trying to implement your own dragging code.

I made it work perfectly
The object in run time look much like
a Delphi object in design time
It takes the object (TEdit) and replaces itself for the object and looks like a object to Move and when finished puts TEdit in its new positioned place on the form
What I did not put in was stepped movements!!!

You can inspire from this DelphiTips.ObjectLinkEditor, that currently serves a basic Object diagram implementation, but can be adapted for any similar cases, including yours

2 Likes

This is a description about objects focused to delivering graphic screen objects in a form on the screen as a reader can relate to screen objects in a form. When the reality is about managing application data and to put many visible screen objects in a Form to allow the user to manage that data. As an application it’s about managing all types of data effectively to deliver to the user. Object Orientated Programming is a very effective tool to simplify a programmer’s instructions to the programmer to deliver to Micro-Processor that Delphi calls ‘RAD’ and to maintain speed of delivery to the user. If you wrote the code in C++ you will find yourself writing 10 times more notes to remind you what you wrote because of the extra volume if programming code you need to write so you don’t get lost. As like a file that compartmentalizes data and gives it a name, then the file is further compartmentalized into a folder and then to the drive that holds many files. So Object Orientated Programming effectively enables the programmer to compartmentalize the control instructions with a grouped set of procedures and functions with its own separate management data for an identified type of data. The limitations are size of computer to store, programmers ability and imagination and nothing else stands in the way.
AI that does not use Object Orientated Programming yet, but takes an English word up to about 18 characters long and turns it into a 4 byte floating point Number, saving a lot of RAM space. And so a tenser of floating point Numbers is a sentence that describes a task. It is only another way to compartmentalize data in a computer to an identifiable fast to access small space. Computers are good with managing numbers, and so 4 bytes is better than 18 and read with 1 Micro Processor instruction.
First Object Orientated Programming effectively starts with the Object Orientated Complier effectively linking a record or a list containing many named data types with a related set of procedures and functions. The procedures and functions do not get repeated as the 2nd and more same objects are created but each object’s record of data is created and allocated out in its own separate space and is the control data. From the base object often named TObject a descendant object built from the record of data, procedures and functions of the object it is built from (TObject) and this can be done a number of times over, example Delphi’s core of screen objects starts from TObject and builds through to TPersistent, TComponent, TWinControl, and on until its final screen object is reached. Each one of these descendant objects incorporate features for a use TPersistent, enables copying of data between objects and many basic object functionally, TComponent enables its self to be held in a form to be identified in a TForm. The capacity to identify a Component in a form means a pointer can locate the object in relation to a TForm to access all sorts of Component changes when needed. TWinControl enables to identify a 2 dimensional area on the TForm, and then descendant objects use a canvas in that area to display information to the user of the form. It is important to define areas in a form so a TWinControl descendant is displaying within its given defined area.
So compartmentalizing can take so many angles that programmers have not began to think like make a object that holds many floating point Numbers. Turns the sentence into a tenser, then makes the AI comparisons between other similar objects. So this is an example of managing data that has never been done before so as a programmer you have to be on the very edge to go where no man has gone before and is very popular with users and users will love you all over.
So with the over view of the use of objects there is a mentality of using a language, the terminology and the many little rules that apply. And every computer language has its own differences, many now are script style languages that are convent to programmers for a number of reasons but slower or something else. It’s important to try different languages and learn the basic pros and cons and what fits you. In my opinion Object Orientated Programming is a lot more to learn but you are a little foolish to ignore Object Orientated Programming because what is important - more writing to do something or use more brains.

2 Likes

Huge block of text - ignored… how about some paragraph breaks? Pretty please

1 Like

So this is
1/ take the object by TMove
2/ move the object
3/ menu to finish the move - TMove is destroyed
4/ Visibility of object restored and located to TMove’s location

5/ LBMove := TMove.Create(Self, Picker, True, False, True);
takes up the date time picker True, False, True sets Width, Bottom, And Moveable settings. TMove is a TCustomControl desendant becuse it has a canvas to draw its self on

So now I’m making screen components with added labels, and a TImage in a Panel to give sides

There used to be, a LONG time ago, a suite of components that did this. I built an entire system for BreastScreen NSW that had a forms designer as part of the software that went live in 2001. We stored the meta-data that captured the data that was required, so the data model was dynamic and was designed as part of the software, and the forms design allowed the users to design the form for data capture/display

Development cost was about $2-3M, was live at a couple of the 9 BreastScreen services in NSW, and I did a tender for BreastScreen SA to for them to use the system. It created a version of an electronic healthcare record too, that could be integrated across different healthcare areas. It was a generic system and could have been used “as is” for other screening programs

What happened? Internal NSW Health politics, and since the new “masters” didn’t want to use me as a software provider, they paid a New Zealand firm $7M to build a replacement, and that went live in the late 2000s to replace what I had rolled out. I did some ADUG presentations in the late 90s and early 2000s about the technology I was building

You could maybe give another … either to reiterate what was happening back then … or to discuss what would be done differently today … ? :grinning:

It frustrates me how organizational politics work sometimes
I see this same thing happen in New Zealand too

A wage payout system by New Zealand teachers nation wide with IBM
been operating very well with a large original design fee in the 1990’s by Labor gov
Politics thought in 2015 wage payments were not been accountable enough
by a national government. and their it started IBM won the contract again 18 million to a end blow out to 40 million plus that we did not get the end fee in the press (embarrassment). A major problem was a mythical identification that their was an issue and a creation image of the labor party is to look bad. Translating what the issue or problem was of cause had to look complicated in the press but some how the database had to deliver more information for checks in the system. A key point was the data in the main frame was to be expanded on and not manually rebuilt again. Have you ever seen how heavy a IBM database is - you do not want to look as only IBM uses it. The teachers union jumped up and down over breaches of privacy big time.
The saga was 2 years plus and a bad look to the national party with the fix it politicians all over it. I ask the teachers now and the payment system from their end is identical to what it was. What did you spend 40 million dollars on? I think the new system had a few more data base fields added in the end that did nothing else.

I think your case was a new manager that did not understand what your product’s target goals were
1/ had other idea’s
2/ Bla Bla Bla
So communication is the problem big time

But I’m doing things very different to you
I have a working registry of my own that is not connected to the windows registry at all.
It saves information to a file or files
it has keys
It stores all that little information and it stores pictures, streams and bigger data as well
I have included TPoint and TRect as well.
I can include anything I like

What you have there is a database.

Description of MySQL, SQL Server, PostgreSQL, JSON, XDATA:

  • It saves information to a file or files
  • it has keys
  • It stores all that little information and it stores pictures, streams and bigger data as well
  • I have included TPoint and TRect as well.
  • I can include anything I like

Correct, that’s a database.

2 Likes

Lex doesn’t have time for databases Ian, he’s got too many more wheels to reinvent!

2 Likes

I have built a registry style data base of my own
it contains common Delphi types of data, pictures, streams…
basically its a database that has a common set of fields the user sets and can search from.
And then as the user increases the database he can add as he wishes in each page