pritaeas commented: Good examples +14
Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster
Glad that helped. Good luck.
You misunderstand basis. Any program itself contains a message loop. At your service, it is not. When you start your service, it starts a thread. More service, do nothing, nor any instructions there for this reason it completes its work. On this you and inform.
In order for service has not ended, you need to implement event implementation. See the attached example. Just pay attention that the cycle is better to check the property Terminated. This property is true when the service portebuetsya completion. Otherwise you risk to be able to stop him. This also applies to Thread.
Implementation of SQL in the cycle seems unlikely. Obviously you need a single execution of this command. Consequently, the team should be run at the coming of the events (eg onset of a certain time). Therefore, one should check in the loop is not the right time has come. If the time has come - the command (it is quite possible to run n
All true. If the service does nothing - it stops. I've attached an example that works. I checked. I hope you know that the first service must be registered in the system? For this command (Administrator rights are required):
ADAMservice.exe /install
You are not quite right uses components. I do so:
private
ADOConnection: TADOConnection;
ADOQuery: TADOQuery;
.......
procedure TTestService.ServiceStart(Sender: TService; var Started: Boolean);
begin
ADOConnection := TADOConnection.Create(nil);
ADOConnection.ConnectionString := 'bla..bla'; //
ADOQuery := TADOQuery. Create(nil);
ADOQuery.Connection := ADOConnection;
ADOQuery.SQL.Text := 'bla bla';
end;
I also do not understand why you are using a thread. Service is also a thread. He has the appropriate means.
procedure TESABExchangeService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
do something
ServiceThread.ProcessRequests(false); // message queue
Sleep(50); // It is necessary that would not load the processor
end;
end;
Put a file with an example of work. This module was written by me for their own needs. You can easily rasshiret it to their needs.
Are you doing something wrong. I've done, everything works fine. Show your code.
What is the difficulty. You have already prompted all that is required. Think beyond yourself. This is an elementary task.
I do not understand why you need random numbers. 12,13,14 - this sequence.
uses
Math;
....
var
d: integer;
begin
d := RandomRange(10,100);
end;
SvcMgr.TEventLogger
This code works the same in office XP,2003,2007. There does not specify the version of office. Checked it works. If Microsoft what it has not changed that will work in 2010.To clarify the version you want to use something like "Excel.Application.12"
I think the traditional approach is simpler.
var
fObject: Variant;
begin
fObject := CreateOleObject('Excel.Application');
if not VarIsEmpty(fObject) then begin
fObject.Visible := true;
fObject.IgnoreRemoteRequests := True;
fObject.WorkBooks.Open(FileName, ReadOnly:=false);
fObject.ActiveSheet.Cells[1, 1].Text := 'Hello world';
end;
Try to start counting from 1. I have not worked with the components, always use another method. I know that almost all the indices in the COM Excel ticking is from 1.
Try this. I have not tested the speed. Just as an option.
procedure TForm1.Button1Click(Sender: TObject);
var List: TStringList;
begin
List:=TStringList.Create;
try
List.Assign(ListBox1.Items);
List.CustomSort(TStringsSort);
ListBox1.Items.Assign(List);
finally
List.Free;
end;
end;
function TStringsSort(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result:=-CompareStr(List[Index1],List[Index2]);
end
Use COM.
fObject := CreateOleObject('Excel.Application');
Just Draw in the OnPaint event and everything will be okay. Or call the drawing functions from this event.
In this matter, I gave an example (attached file):
http://www.daniweb.com/software-development/pascal-and-delphi/threads/356130
Knowledge comes with experience. Experience - do not spend on drink. I'm glad I could help.
Project -> Options -> Application -> Enable Runtime Themes - uncheck this
Write a task that is necessary. The code is not completely understood.
As I understand it there are 2 of the array. Need to multiply their elements and get summ? If yes, then this:
sum := 0;
for i:=1 to 80 do
begin
naspole1[i]:=pole1[i]*pole2[i];
sum := sum + naspole1[i];
writeln(naspole1[i]);
end;
writeln(sum);
In your case this is not visible. I do not understand what exactly you need. Write more, or give a full job.
nas := 0;
for i:=1 to 80 do
begin
naspole1[i]:=pole1[i]*pole2[i]+nas;
if naspole1[i] >= 10 then
begin
naspole1[i] := naspole1[i] div 10;
nas := naspole1[i] mod 10;
end;
write(naspole1[i]);
end;
Quite simply, I do not understand the difficulty. Moreover, this effect can be dobitsya and in other ways. The easiest to use the component TPanel. Another set of TLabel property AlignWithMargin: = true and set the necessary margin Margin.Top: = n.
Something like:
http://www.delphisources.ru/pages/faq/base/create_new_table.html
For more information, read the help for Delphi
TLabel that can not do. Tsf need to use the DrawText API function with the keys: DT_CENTER + DT_VCENTER + DT_SINGLELINE
Pre TRect specify where you want to write an inscription.
If you do not know what size is needed, then add key DT_CALCRECT. When this key TRect will be calculated but the inscription will not be bred. That would bring the inscription should call the second time, without the key.
http://msdn.microsoft.com/en-us/library/ms901121.aspx
Almost all that is written for Delphi important for Lazarus. Because search for information for dolphins if you can not find Lazarus.
I'm trying to say that you are using an array in vain for the TImage. If you lozhish component on the form, the form is aware of this component. Accordingly, we can use it (see property Components [] and Controls []). These properties are available for all window components. The only thing you have used two-dimensional array, and these properties - a linear list. This is not a problem, you can always calculate the row and column in a linear array, knowing the width and height of the matrix.
In addition, instead of the array is much more convenient to use the class TObjectList.
There is no time, but later I'll show an example of how you can use these properties to emulate the array. I think many students at this site will be useful. I myself have not a student.
Learn to read the documentation. The note says it all. I already wrote that you invented the wheel in an array. Now you again that it invents. It's time to read and not poke your finger into the sky.
way 1
procedure TSecondForm.Button1Click(Sender: TObject);
var
bmp: TBitmap;
idx: Integer;
begin
bmp := TBitmap.Create;
try
for idx := 0 to ImageList.Count - 1 do
begin
ImageList.GetBitmap(idx,bmp);
Canvas.Draw(0,idx*bmp.Height,bmp);
end;
finally
bmp.Free;
end;
end;
way 2
procedure TSecondForm.Button2Click(Sender: TObject);
var
idx: Integer;
begin
for idx := 0 to imageList.Count - 1 do
ImageList.Draw(Canvas,0,idx*ImageList.Height,idx);
end;
I would have done something like this code:
procedure TSecondForm.Button3Click(Sender: TObject);
var
bmp: TBitmap;
idx,i: Integer;
begin
bmp := TBitmap.Create;
try
i := 0;
for idx := 0 to ComponentCount-1 do
if (Components[idx] is TImage) then
begin
ImageList.GetBitmap(i,bmp);
(Components[idx] as TImage).Picture.Assign(bmp);
Inc(i);
end;
finally
bmp.Free;
end;
end;
Problem in this line:
hTargetWnd := FindWindowEx(0, 0, nil, PChar('WM_COPYDATA-Receiver'));
You have incorrect settings. We had to read. The third parameter - the window class name to search for, and the fourth - his title. If you specify these two parameters, the search will give 100% result. If you specify only one of them - not the fact that he would find.
I'm a bit at the same time simplify the code and adapt it to Delphi2009 (I write this version). This line calculates the amount of data transmitted. In D2009-line PChar = PWideChar. That's how we calculate the exact size - SizeOf (PChar):
cbData := Length(Edit1.Text) * SizeOf(PChar);
Complete working example, see the attached file.
Give a look at your code. Without seeing the code is hard to say what the problem.
By the way, if you want to click, you can directly send a message to the button. Likewise, using FindWindow
Query.Parameters.ParamByName('DateReceived').AsDateTime := Invoice.DateReceived;
P.S.:
date can be increased simply, use IncDays/DecDays (in DateUtils)
Invoice.DateReceived := DateUtils.IncDays(now,2);
Examine carefully classes. You invented the wheel.
Note the two properties have TForm1 - Controls [], and Components []. Number of them ControlsCount and ComponentsCount.
You put in design time 32 TImage component on TForm1. Hence Form1 already contains an array of pointers. Likewise, instead of TForm could be such TPanel.
See your TImage can be as follows:
for i: = 0 to Form1.ComponentsCount-1 do
if (Form1.Component isTImage) then
(Form1.Component as TImage). Picture.Assign (...);
Where is the question?
function IntToBin( Value: integer; Digits: integer ): string;
begin
result := StringOfChar ( '0', digits ) ;
while value > 0 do begin
if (value and 1) = 1 then
result[digits] := '1';
dec (digits) ;
value := value shr 1;
end;
end;
You better take advantage of the components of Indy (TidHTTP) and use threads TThread.
// Static show
procedure TForm1.Button1Click(Sender: TObject);
begin
// Form2.Show;
Form2.ShowModal;
end;
// dynamic creation, show, free
procedure TForm1.Button1Click(Sender: TObject);
begin
with TForm2.Create(self) do
try
if ShowModal = mrOK then
ShowMessage('Hello world!')
else
ShowMessage('Bye world!')
finally
Free;
end;
end;
procedure Wait(ms: integer);
var
bt: DWORD;
begin
bt := GetTickCount;
while (GetTickCount - bt) < ms do
Application.ProcessMessages;
end;
for delphi:
procedure Wait(ms: integer);
var
bt: DWORD;
begin
bt := GetTickCount;
while (GetTickCount - bt) < ms do
Application.ProcessMessages;
end;
1. You can use the class object list TObjectList. Only need to take care of his creation and removal.
private
btn: TObjectList;
procedure TForm1.FormClick(Sender: TObject);
begin
with Btn.Items[Btn.Add(TButton.Create(Self)] do
begin
OnClick := ButtonClick;;
Left := 8;
Top := (((Btn.Count - 1) * Height) + 8);
Parent := Self;
end;
end;
2. Can be even easier. A parent already knows all her children.
procedure TForm1.FormClick(Sender: TObject);
begin
with TButton.Create(Self) do
begin
OnClick := ButtonClick;;
Left := 8;
Top := (((Self.ControlCount - 1) * Height) + 8);
Parent := Self;
end;
end;
Access to any button can be so
procedure TForm1.FormClick(Sender: TObject);
var
i: integer;
begin
for i:=0 to Self.ControlCount-1 do
if Self.Controls[i] is TButton then
with Self.Controls[i] as TButton do
begin
Caption := 'Hello world!';
end;
end;
Need to program but decide what the flag state or leaving any other sign for the program B.
In pocet what value? Do that and will be happy:
function kolik(pocet:integer; retez: string):integer;
const
pocent = 5;
var
p: array[1..pocet] of integer;
pomocna,j,i,k,l,od,nep:integer;
No need touse Timer. It is not safe (low priority) and is not correct. The correct solution would be to use the component and its TActionList. This component is specifically designed to do this. It gives a centralized management of form elements. Sure to check out and see the attached example.
Use TThread.
Read more about "design patterns". "Memento" - what you need.
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
if "infor[1].name" is string, then is very simple.
var
S: string;
P: integer;
begin
S := 'infor[1].name';
P := Pos('.',S);
if P > 0 then
Delete(S,P,1);
end;
if the "infor[1]" - an object, then you need to read a book on OOP or career change.
type
TDataBytes = array[0..1023] of byte;
TOnData = procedure(const Buff: TDataBytes; const DataLen: word);
Olaylar = class
private
FOnRx: TOnData;
FOnTx: TOnData;
procedure SetOnRx(const Value: TOnData);
procedure SetOnTx(const Value: TOnData);
published
property OnRx: TOnData read FOnRx write SetOnRx;
property OnTx: TOnData read FOnTx write SetOnTx;
end;
procedure Olaylar.SetOnRx(const Value: TOnData);
begin
FOnRx := Value;
end;
procedure Olaylar.SetOnTx(const Value: TOnData);
begin
FOnTx := Value;
end;
It's very simple. Use components Indy (TIdHttp) http://www.delphigroups.info/2/5/487672.html
or http://www.realthinclient.com/ (TrtcHttpClient)
Yes, I forgot to say that this method should be used when dynamically creating dialogues. This will save memory, because memory will be allocated and freed as needed. What would it work to remove the line to automatically create a form. This can be done from the menu in two ways:
1. Open Project -> View source and remove Application.CreateForm(TOKRightDlg, OKRightDlg);
2. Open Project -> Options -> Forms and move TOKRightDlg from Auto-create form to Available form
This requires some programming experience. Therefore recommend that you do not do this, let the form is automatically created. Just a little change code:
procedure TNeuralNetworkInterface.Button2Click(Sender: TObject);
begin
with OKRightDlg do
if Execute() then
begin
NN.createNetwork(OKRightDlg.NrOfInput,OKRightDlg.NrOfOutput,OKRightDlg.useHidden);
end;
end;
Dynamic creation of forms related to professional programming. This greatly saves memory when the program lots of dialogue. It is also not very good to automatically create dialogues that are rarely used. Eg "About".
This is a good style. But beware! If you forget to free memory, then get a leak! Program during the work will always spend more and more memory. Windows did not like, the computer begins to slow down.
You can do this:
OKRightDlg := TOKRightDlg.Create(self);
OKRightDlg.DoSometing();
OKRightDlg.Free;
However, it is dangerous. If the method DoSometing an exception is thrown, then the method is not called Free and you get a memory leak.
Use this:
OKRightDlg := TOKRightDlg.Create(self);
try
OKRightDlg.DoSometing();
finally
OKRightDlg.Free;
end;
Very simple. In the main form, you give a link to the second module. In the main module creates an event handler by pressing a button and write code like this (in the second module does not need links to the main module):
unit MainForm;
..........
uses
SecondForm;
TMainForm.Button1Clicck(Sender: TObject);
begin
with TSecondForm.Create(Self) do
try
if ShowModal = mrOK then
MyProcedure(ParamA,ParamB);
finally
Free;
end;
end;
ParamA следует понимать как SecondForm.ParamA
Hilarious you're a guy. Study did not want. Think you do not want. Do you want to "copy-paste" to get the world-famous "Indian code"? Well, it's your business. I do know how to do it, I do not suffer.