Thanks pirtaes, got it working like a treat now and I've even started programming with multithreading :D. You truely are a ledgend on the DaniWeb Delphi forums :D.
Thanks pirtaes, got it working like a treat now and I've even started programming with multithreading :D. You truely are a ledgend on the DaniWeb Delphi forums :D.
Thanks for your fast response pirtaeas, I thought TTimer was a simplified way of using multiple threads but I guess I'm wrong? Or maybe it's just not powerful enough. I guess I'll have to give the complex way a try.
Have you got any neat tutorials for multithreading for starters?
Basically I have a Delphi application which downloads some data on run time, it basically executes Form.OnCreate; and then ENABLES a TTimer component to do the downloading. This has been working fine for me as at least the user sees the interface whilst it's loading but now I have a problem.
I am trying to update the FormCreate so it has a loading icon like this:
http://logd.tw.rpi.edu/files/loading.gif
I have already created about 9 images for my own loading icon and I have it animated using ANOTHER TTimer component which is also enabled in the Form.OnCreate BEFORE the downloading TTimer. But the problem I have is the loading icon just freezes whilst it is loading/downloading and only starts working AFTER the downloading/loading is finished, making it completly useless :(.
Can someone help me to have a smooth loading bar like that at the same time it is downloading? Is there a certain way to create these things?
Nevermind got it to work, silly me using the tutorials I should have known that cbData was a memory type. I was basically allocating an incorrect amount of memory for the cbData, the correct calculation for that line is:
CopyDataStruct.cbData := (1 + Length(SendStr))*SizeOf(Char);
Ye you can use code like this:
If RadioGroup1.ItemIndex = 0 Then
Begin
//Do something
End;
Ofcourse the first item in your radio group would have a ItemIndex of 0 and the next one would be 1 and so on.
Basically I'm running into issue, I have a Global Keyboard hook in a DLL, whenever it captures a key it uses WMCopyData to send the keycode over to the MAIN application. The problem is when the main application gets the key code it seems to be corrupt/changes in value.
Here is my code for the DLL sending the data:
Procedure PassData(wParamCopy : Word);
Var
SendStr : String;
CopyDataStruct : TCopyDataStruct;
RecHandle : THandle;
Begin
SendStr := IntToStr(wParamCopy);
CopyDataStruct.dwData := 0;
CopyDataStruct.cbData := 1 + Length(SendStr);
CopyDataStruct.lpData := PChar(String(SendStr));
RecHandle := GetHandle('AppName');
If RecHandle = 0 Then
Begin
ShowMessage('Communication Error!');
Exit;
End;
SendMessage(RecHandle, WM_COPYDATA, 0, Integer(@CopyDataStruct));
End;
Recieving code in the main application:
Procedure TfrmMain.WMCopyData(var Msg: TWMCopyData);
Var
S : String;
Begin
S := PChar(Msg.CopyDataStruct.lpData);
ShowMessage(S);
End;
Also a private declaration in the main application goes like this:
Procedure WMCopyData(var Msg : TWMCopyData); Message WM_COPYDATA;
Now say the DLL returns "65" as the keycode when the user press the "A" button, it will pass on the integer type 65 to the "PassData" procedure which will convert it into a string and then into a PChar ready to be sent over to the main applicaiton.
When it does the "ShowMessage(S)" in the main application it ends up showing "65껾玧" clearly something went wrong in the conversion/data sending, can anyone help me out?
I just read your edit and this is the second time someone has mentioned cURL to me, the thing is version of Delphi I use doesn't support cURL properly but I can POST data. I have never used cURL before and don't understand what it does exactly but is POSTing data to the script a good alternative, can you help me out with a explanation of how cURL can help.
Well I'm just a developer really, I can have access to the DB's but I would really prefer not to go near them. My aim is to use the MyBB interface to do all the complex stuff such as putting data onto the DB and hasing the logins.
Also my program has multiple users so it has to be a viable solution which can keep them in mind.
Ye, basically I have the forums on a sub-domain called something like forums.domain.com and the script will be on another sub-domain called something like scripts.domain.com/script.php
Basically, I have a program in Delphi which POSTs data to a MyBB script on a server, when the MyBB script recieves that POSTed data it is supposed pass that data onto a MyBB forum and use it to post a new thread.
The only problem is I have no idea how to do the second part which is sending the data to the MyBB forum.
Potential problems I can see is:
- Logging in?
- Thread title and thread content?
Also I need to search the forum before posting, like if a certain thread title already exists then it posts a new post but if the thread title does not already exist then it posts a new thread.
I've had a look at API's but the only thing I've found is APIs which return forum data rather than POST forum data so I'm a bit lost on what to do now. Can anyone help? Thanks a million!
How do I check if any window is maximized? I've got a program which sends keystrokes to that window but the problem is it will send keystrokes to any application that is running on my PC at the moment, so I wanted to prevent this by making it only send the keystrokes if that program is running.
Can anyone help? Maybe use notepad.exe as a example, I've got functions to get handles of any program too so you don't need to add that in, just comment :D.
Well you could just do:
If StringGrid1.Cells[1,1] = 'Toast ' then
begin
time_queue := time_queue - EncodeTime(0, 5, 0, 0);
end;
I'm not to sure about TTime but I've used TDateTime before and maybe you can do something like this:
var
Time : TTime;
begin
Time := Now;
Time := Time + EncodeTime(0, 5, 0, 0); //Adds 5 minutes to Time
ShowMessage(TimeToStr(Time));
end;
See EncodeTime: http://www.delphibasics.co.uk/RTL.asp?Name=EncodeTime
I think this is what your trying to achieve, the problem with incrementing time is the format and the way it works, you need to increment time with time variables as opposed to standard integers.
Just to further help you out, the colors of the disk are defined by using a palette like this:
LineCol := ColorToRGB(clRed);
Re2 := GetRValue(LineCol);
Gr2 := GetGValue(LineCol);
Bl2 := GetBValue(LineCol);
BackCol := ColorToRGB(clBtnFace);
Re1 := GetRValue(BackCol);
Gr1 := GetGValue(BackCol);
Bl1 := GetBValue(BackCol);
ABitmap := TBitmap.Create;
Try
ABitmap.PixelFormat := pf8bit;
ABitmap.Width := Image1.Width;
ABitmap.Height := Image1.Height;
GetMem(pal, SizeOf(TLogPalette) + SizeOf(TPaletteEntry) * 255);
Try
pal.palVersion := $300;
pal.palNumEntries := 256;
LineCol := RGB(Re2, Gr2, Bl2);
BackCol := RGB(Re1, Gr1, Bl1);
For I := 0 To 255 Do
Begin
pal.palPalEntry[i].peRed := round(i / 255 * (LineCol AND $FF) + (255 - i) / 255 * (BackCol AND $FF));
pal.palPalEntry[i].peGreen := round(i / 255 * (LineCol shr 8 AND $FF) + (255 - i) / 255 * (BackCol shr 8 AND $FF));
pal.palPalEntry[i].peBlue := round(i / 255 * (LineCol shr 16 AND $FF) + (255 - i) / 255 * (BackCol shr 16 AND $FF));
End;
hpal := CreatePalette(pal^);
If hpal <> 0 Then ABitmap.Palette := hpal;
Finally
FreeMem(pal);
End;
For Y := 0 to ABitmap.Height - 1 Do FillChar(ABitmap.Scanline[Y]^, ABitmap.Width, 0);
ACenterX := StrToFloat('100');
ACenterY := StrToFloat('100');
ARadius := StrToFloat('50');
ALineWidth := StrToFloat('1');
AFeather := StrToFloat('1');
DrawDisk(ABitmap, ACenterX, ACenterY, ARadius, AFeather);
ABitmap.PixelFormat := pf32bit; //Convert back to normal format so normal Delphi canvas colours work
Image1.Picture.Bitmap.Assign(ABitmap);
Finally
ABitmap.Free;
End;
Once the palette is defined then the procedure is called
Alright thanks mate, I don't think I have the knowledge to modify additional anti-aliasing in this :S
I'm working with this rather popular DrawDisk procedure which pretty much anti-aliases a circle and draws it, filling it and the background in the process. At the moment the procedure call only lets you modify the background color of the WHOLE canvas and the fill color of the line. Have a look:
procedure DrawDisk(Bitmap: TBitmap; CenterX, CenterY, Radius,
Feather: single);
// Draw a disk on Bitmap. Bitmap must be a 256 color (pf8bit)
// palette bitmap, and parts outside the disk will get palette
// index 0, parts inside will get palette index 255, and in the
// antialiased area (feather), the pixels will get values
// inbetween.
// ***Parameters***
// Bitmap:
// The bitmap to draw on
// CenterX, CenterY:
// The center of the disk (float precision). Note that [0, 0]
// would be the center of the first pixel. To draw in the
// exact middle of a 100x100 bitmap, use CenterX = 49.5 and
// CenterY = 49.5
// Radius:
// The radius of the drawn disk in pixels (float precision)
// Feather:
// The feather area. Use 1 pixel for a 1-pixel antialiased
// area. Pixel centers outside 'Radius + Feather / 2' become
// 0, pixel centers inside 'Radius - Feather/2' become 255.
// Using a value of 0 will yield a bilevel image.
// Copyright (c) 2003 Nils Haeck M.Sc. www.simdesign.nl
var
x, y: integer;
LX, RX, LY, RY: integer;
Fact: integer;
RPF2, RMF2: single;
P: PByteArray;
SqY, SqDist: single;
sqX: array of …
Thanks! I've seen AlphaBlend before and never managed to get it to work. This procedure sure looks like it will though, you are great at finding these :D.
Just a question though, I have no idea how to call it, I.e. how can I use this procedure to turn a TImage into (for example Image1) Bitmap and then make it transparent and then draw over it using canvas tools such as MoveTo and LineTo
Hello, basically I want to have two TImage components, one I will use and using the Bitmap tools in Delphi I will create a background. In the second TImage I will create objects which move around the custom background but I still want the first TImage to be visible.
The problem I have is when I create the second TImage ontop of the first one the Canvas creates a huge white square over the background image making it impossible to see, how can I make the second TImage transparent so that the background is always visible and does not change regardless of the movements in the second one.
Ye that sounds like a much more suitable solution, have you got any example codes or websites with intros to this?
Ye that's what I was thinking but the class has moving objects, i.e. changing variables and it needs to record all the different changes so would I have to WriteComponent each time and would it append the data?
Hello, basically I am making a program which uses OOP to draw objects onto a canvas and they constantly move, I am making a feature which will save the position variables as the objects move each time and then once a file is outputted it can be read again and the objects can be spawned and moved in the exact same locations.
The problem I have is decided on the best solution as I am new to OOP, I was thinking I could store all the location variables in a separate Type Record and constantly BlockWrite that data, possibly using a dynamic array. But I am having problems with BlockWrite and it is slightly buggy in my prototype scripts as the pointers end up causing read and write errors with the dynamic array.
I was thinking should I carry on trying to use BlockWrite and if so can someone help me with some code which could use dynamic arrays to store data like this. Or should I look into another way of saving such as Object Persistence and keep all variables inside the Object Class? (including the movement ones).
Edit: The problem with the dynamic array is that it wipes the data of the counter variables after calling BlockRead, which tells me how many arrays were made and how many need to be displayed/read, it changes the value to anything, pretty much erases it.
Ahh ok great, now I just need to know how I can install it :P. There is a bunch of files in there and I have no idea how to get them to work. Can anyone help me? Do I have to open up one of the files in Delphi? If so which file should I open, there are a lot of demos and tests in there :S.
I'm not sure which one is the right one for Delphi but I meant this:
http://www.progdigy.com/?page_id=7
Is it right?
I'm having trouble getting GDI sample codes to work, I've seen the external packages and downloaded them but I couldn't get the same code to work and I believe it's because I don't know how to install the GDI packages properly, can anyone help me?
Thanks! The constructor was the solution, how do I mark this as solved? Thanks again.
Basically I have a object class like this:
Type TSomething = Class
Private
Blah : Integer;
Public
Procedure DoSomething;
End;
Type TSecond = Class(TSomething)
Public
Procedure DoSomethingNew;
End;
Procedure TSecond.DoSomethingNew;
Begin
ShowMessage(IntToStr(Blah));
End;
...and the code to call the classes is:
Try
Something := TSomething.Create;
Something.Blah := 5000;
Finally
Something.Free;
End;
Try
Second := TSecond.Create;
Second.DoSomethingNew;
Finally
Second.Free;
End;
Now even though I assign the value "5000" to the variable Blah in the main class, when I try to check the value of Blah in the second class it returns a null (0) value. Why is the variable wiped when I have assigned a value to it already.
How can I overcome this problem? I am new to object orientated programming so I'm not too sure why this isn't working, is it because I am freeing the memory? I was thinking of having one main class which has variables which all the sub-classes will use, but the main classes variables keep on getting wiped whenever I check them in sub-classes.
-Nevermind for now-
Anyway is fine really, I guess I would prefer from the center.
Heya guys, basically here is some code for a simple example program:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
img1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Image : TBitmap;
begin
Image := TBitmap.create;
Image.Width := 800;
Image.Height := 600;
img1.Picture.Graphic := Image;
With img1.Picture.Bitmap.Canvas
do
begin
Pen.Color := clRed;
Pen.Width := 5;
MoveTo(100,100);
LineTo(100,120);
MoveTo(95,120);
LineTo(105,120);
MoveTo(100,110);
LineTo(110,113);
MoveTo(100,110);
LineTo(90,113);
end;
end;
end.
It's basically a program which simply draws some random canvas art. Here is a picture of the program once it is run:
[IMG]http://i55.tinypic.com/24pxoqv.png[/IMG]
The problem I have is rotating this art. Rather than going the long winded way of increasing and decreasing numbers in the MoveTo and LineTo procedures is there a way I can rotate this canvas art at any angle (e.g. right now it is facing north or 0 degrees but rotating it 45 degrees would make it face north east). Now I'm not good at copying functions from the internet so if you are going to help me, please paste the additional code inside the code that I have provided above and provide a brief explanation of how it works.
Thanks guys, your awesome!
Hey, thanks for the reply mate. Basically I am also using a older version of Delphi (Borland Delphi 7). Anyway I decided I am not going to use external images for this program, I am instead going to draw the images with Delphi's canvas feature however I have a new problem with that so I'll be making a new thread to explain it and I'll show my code.
Well I'm making a program where multiple images will be used but I don't know how to make the images transparent, since Delphi is only allowing me to use .jpg images instead of transparent .png images. It ends up giving my images a white sqaure block around them and ruins things such as backgrounds.
I've heard about keyboard hooks before but I can't really understand how to make them as there isn't much tutorials on it. I was wondering if anyone could make a very simple keyboard hook which detects me pressing the UP ARROW key and explain the code to me. Also are keyboard hooks used for games?
Ok what you just said is completly new to me again lol, thanks very much for your help though :D.
You know how I learn best, is if you zip up a example file.
The screen I will be using is for my computer screen at College, it has a screen resolution of 1280x1024 but just incase it would be nice if you can use DT_CALCRECT. Just make it so I can show a label in the middle of the screen and 180px from the top.
If you could do that then once again I'm going to be ever so greatful :D :D :D. Like last time, your help was much appreciated :).
There are all sorts of different loops which can be used for the same purpose but some loops are better at doing things than others. A For loop is mainly used when you want to know how many times you will require to loop e.g. you want to loop 10 times to check 10 different names a user has entered.
Where as something like a while loop is used when you really don't know how many times the loop is going to happen, when it depends on what the user does with your application.
The above post shows you how to convert the for loop to a while loop which I think is what your looking for and it's a good answer. But remember the syntax for for loops and while loops is different and if your new to Java I suggest you follow some tutorials on how to makes different types of loops and once your confident then you should try using different types of loops in your own test programs.
If you get stuck again feel free to e-mail me on "giganticknowledge@live.co.uk" lol. I'm sure I can get in touch to help you out, or you could post another topic here.
Basically I have a label which I do the following with on start up of my application:
with Label1 do
begin
Caption := 'Computer Locked';
Align := alClient;
Alignment := taCenter;
Top := 400;
end;
Now the problem I have is the alClient and taCenter work perfectly making the label in the middle of the screen but the problem is it display the label right at the top of the screen in the middle. I want to display the label in the middle of the screen and then down from the top by 400 which is why I used the code "Top := 400" but it makes no difference and instead the label displays as if "Top := 0" which I have no idea how to fix. Any ideas?
Thanks it worked.
Ahh your environment variables need to be set up.
This is what you need to do:
1. First you need find the jdk1.6.0_24 folder as this is the latest version, the inside the jdk1.6.0_24 folder find a folder called "bin", open this folder and you will see a load of files including the "javac.exe" right click on any of these files and click on properties.
2. Now you will see a windows menu pop up, find the label where it says "Location", once you find it copy what it says for the location as this is the path you need to input into the environment variables.
3. Once you copy the path, click on the Start button, then click on Control Panel.
4. In the Control Panel search box type "environment" and wait for the results, you should see something like "Edit the system environment variables", click on this and if you are prompted for admin permission accept it so you can move on.
5. Now you will see a set up menu pop up, in the bottom right corner you will see a button called "Environment Variables" click on this.
6. You will now see the environment variables menu, here there will be two types of sub menus where one is labeled "User variabls for <YOUR USERNAME>" and the other one is "System Variables" all you need to do is in the system variables click the "New" button.
7. Once you …
My source code is pretty much the exact same source code you gave me lol... I will put this code in my main programs later but first I just want to learn and understand how this works before I do that. Click on the below link, it shows you the first application and the second application.
ttp://i51.tinypic.com/123a4ih.png
In the first application where the edit box is, when you type in the Caption for the second application and hit "Button1" it should send the message over right? or so I belive. What actually happens is I get the ShowMessage error as you can see displayed telling me "No Recipient found!" which I think means it does not recognize the second application. Why is this?
Here is the source code for "First Application":
unit oneMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfApp = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
fApp: TfApp;
implementation
{$R *.dfm}
procedure TfApp.Button1Click(Sender: TObject);
var
aCopyData: TCopyDataStruct;
hTargetWnd: HWND;
begin
with aCopyData do
begin
dwData := 0;
cbData := StrLen(PChar(Edit1.Text)) + 1;
lpData := PChar(Edit1.Text)
end;
// Search window by the window title
// Fenster anhand des Titelzeilentext suchen
hTargetWnd := FindWindowEx(0, 0, nil, PChar('WM_COPYDATA-Receiver'));
if hTargetWnd <> 0 then
SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@aCopyData))
else
ShowMessage('No Recipient found!');
end;
end.
Here is the source code for "Second Application":
unit twoMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, …
Thanks you so much for your reply, I have managed to get it working without compiler errors BUT I keep on getting errors with the program itself telling me no reciept is found.
In the first program what should I put in the edit box to make it communicate with the other program? I've tried different names that I saved the application as but it never worked. Any ideas on what window name I should be entering?
Hello guys, basically I have two Delphi applications which I want to communicate and work with each other, the only problem is I don't know how. Can anyone help me create a as simple as possible programs so that when I press a button in the first program, it would send a command to the second delphi program and press a button on the second delphi program.
Is this possible? Can you please help me in details, I have spent hours on the internet with no programs working or any luck. Please help me out guys :D.