A-man Posted August 9, 2012 Share Posted August 9, 2012 (edited) Is there any information available on using events like OnMouseEnter or OnMouseDown in forms? I noticed in the example from the old help guide it used 'Button1.OnClick:= @buttonclick;' to exit the form. The form editor is really useful, but I have no idea where I can learn to use the events. It is not specific to those events, but those are 2 I need especially. EDIT: I am also going to run into the problem of decimal precision with my mandlebrot veiwer. Is there a way to set the decimal precision? Or a way to code it to use quads or something? Edited August 10, 2012 by A-man Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted August 10, 2012 Share Posted August 10, 2012 After you create you form you go to what object you wish to add the event on and add the corresponding event, with a function address then within the function u actually make the procedure do what you need it to do. The Functions name and parameters need to match that of the event you calling. View the example below Run this example and look at the code [scar] type TForm1 = record Form1: TForm; end; var Form1: TForm1; procedure ChangeColor(Sender: TObject); // This is how a TNotifyEvent is setup begin With Form1 do With Form1 do Color := RandomRange(0, 255); end; procedure Form1_Init; begin with Form1 do begin Form1 := CreateForm; with Form1 do begin Left := 376; Top := 174; Caption := 'Form1'; ClientHeight := 202; ClientWidth := 304; Color := clBtnFace; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -11; Font.Name := 'Tahoma'; Font.Style := []; OldCreateOrder := False; PixelsPerInch := 96; OnMouseEnter := @ChangeColor; end; end; end; procedure Form1_SafeInit; var v: TVariantArray; begin SetLength(v, 0); ThreadSafeCall('Form1_Init', v); end; function Form1_ShowModal: Boolean; begin Result := Form1.Form1.ShowModal = mrOk; end; function Form1_SafeShowModal: Boolean; var v: TVariantArray; begin SetLength(v, 0); Result := ThreadSafeCall('Form1_ShowModal', v); end; begin Form1_SafeInit; Form1_SafeShowModal; FreeForm(Form1.Form1); end. [/scar] Quote Link to comment Share on other sites More sharing options...
A-man Posted August 12, 2012 Author Share Posted August 12, 2012 Ok, that makes sense. I guess I'll be more specific. Here is my code I want to execute. The program will be running, and when it gets to a certain point, I want it to call this draw function to display the image on the TImage. procedure draw(Sender: TObject); var i : TSCARBitmap; begin i := TSCARBitmap.create(''); i.loadfrompng('C:\Users\A-man\Pictures\mandlebrot\mandlebrot.png'); with Image1 do i.assign(Picture); end; This doesn't do anything though. I think it is assigning Picture to i, not i to Picture. I'm not sure how to do that. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted August 12, 2012 Share Posted August 12, 2012 Ok, that makes sense. I guess I'll be more specific. Here is my code I want to execute. The program will be running, and when it gets to a certain point, I want it to call this draw function to display the image on the TImage. procedure draw(Sender: TObject); var i : TSCARBitmap; begin i := TSCARBitmap.create(''); i.loadfrompng('C:\Users\A-man\Pictures\mandlebrot\mandlebrot.png'); with Image1 do i.assign(Picture); end; This doesn't do anything though. I think it is assigning Picture to i, not i to Picture. I'm not sure how to do that. Maybe try this, I don't think TBitmaps work in SCAR though: [sCAR] a.Picture := nil; a.Picture.Bitmap := i as TBitmap; [/sCAR] You could always copy the canvas. Try using the CopyCanvas function. [sCAR] program New; var i: TSCARBitmap; a: TImage; begin a := TImage.Create(nil); CopyCanvas(i.Canvas, a.Canvas, 0, 0, sourceW, sourceH, 0, 0, destW, destH); end. [/sCAR] Quote Link to comment Share on other sites More sharing options...
A-man Posted August 12, 2012 Author Share Posted August 12, 2012 Copy canvas is working great. Next question: OnMouseEnter := @draw; works, whereas OnMouseEnter := @click does not work. OnMouseEnter throws a type mismatch for some reason. I think it's because 1 is a TMouseEvent and one is a TNotifyEvent. OnMouseEnter works when I change click() from a procedure to a function, but I don't want it to return anything. Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted August 13, 2012 Share Posted August 13, 2012 TMouseEvent is setup like so: procedure Click(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); This returns the x and y where the mouse was clicked, shift state and what button was clicked. Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 13, 2012 Share Posted August 13, 2012 (edited) Ok, that makes sense. I guess I'll be more specific. Here is my code I want to execute. The program will be running, and when it gets to a certain point, I want it to call this draw function to display the image on the TImage. procedure draw(Sender: TObject); var i : TSCARBitmap; begin i := TSCARBitmap.create(''); i.loadfrompng('C:\Users\A-man\Pictures\mandlebrot\mandlebrot.png'); with Image1 do i.assign(Picture); end; This doesn't do anything though. I think it is assigning Picture to i, not i to Picture. I'm not sure how to do that. [scar]procedure draw(Sender: TObject); var Bmp: TSCARBitmap; begin Bmp := TSCARBitmap.Create(''); try Bmp.LoadFromPng('C:\Users\A-man\Pictures\mandlebrot\mandlebrot.png'); Bmp.AssignTo(Image1.Picture); finally Bmp.Free; end; end;[/scar] Maybe try this, I don't think TBitmaps work in SCAR though: [sCAR] a.Picture := nil; a.Picture.Bitmap := i as TBitmap; [/sCAR] TBitmap works just fine in SCAR, but casting a TSCARBitmap to a TBitmap won't magically make it a TBitmap object... + you should never assign nil to an object property. Copy canvas is working great. Next question:OnMouseEnter := @draw; works, whereas OnMouseEnter := @click does not work. OnMouseEnter throws a type mismatch for some reason. I think it's because 1 is a TMouseEvent and one is a TNotifyEvent. OnMouseEnter works when I change click() from a procedure to a function, but I don't want it to return anything. http://docwiki.embarcadero.com/Libraries/en/Vcl.ExtCtrls.TImage_Events Edited August 13, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
LordJashin Posted August 13, 2012 Share Posted August 13, 2012 [scar]procedure draw(Sender: TObject);var Bmp: TSCARBitmap; begin Bmp := TSCARBitmap.Create(''); try Bmp.LoadFromPng('C:\Users\A-man\Pictures\mandlebrot\mandlebrot.png'); Bmp.AssignTo(Image1.Picture); finally Bmp.Free; end; end;[/scar] TBitmap works just fine in SCAR, but casting a TSCARBitmap to a TBitmap won't magically make it a TBitmap object... + you should never assign nil to an object property. http://docwiki.embarcadero.com/Libraries/en/Vcl.ExtCtrls.TImage_Events Is there a way to, load the TSCARBitmap variable into a TBitmap without saving as a .bmp or image format? This might help some what with the form components for SCAR. I guess you could just use CopyCanvas though... Is there a way to load a TImage component by itself. Like show it onto the screen without it having the form as the parent or anything as the parent? Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted August 13, 2012 Share Posted August 13, 2012 Is there a way to, load the TSCARBitmap variable into a TBitmap without saving as a .bmp or image format?This might help some what with the form components for SCAR. I guess you could just use CopyCanvas though... Is there a way to load a TImage component by itself. Like show it onto the screen without it having the form as the parent or anything as the parent? Why not just use the TSCARBitmap AssignTo function? Thats the whole reason he implimented the assignto function, to make it easier to assign images to TObjects. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted August 13, 2012 Share Posted August 13, 2012 Why not just use the TSCARBitmap AssignTo function? Thats the whole reason he implimented the assignto function, to make it easier to assign images to TObjects. Crap my bad, I thought assign to was only for that type? You know I got right to that point in his video and that i think is where I had to stop because I had to do something. Lol... Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted August 13, 2012 Share Posted August 13, 2012 Crap my bad, I thought assign to was only for that type? You know I got right to that point in his video and that i think is where I had to stop because I had to do something. Lol... Lol, yeah i love the new TSCARBitmap class its awesome! Just gotta get use to it! Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 14, 2012 Share Posted August 14, 2012 When assigning a TBitmap to a form component or it's properties, make sure you do it in a ThreadSafeCall! Quote Link to comment Share on other sites More sharing options...