ผู้เขียน หัวข้อ: delphi  (อ่าน 18828 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้


doramon

  • บุคคลทั่วไป
Re: delphi
« ตอบกลับ #1 เมื่อ: กันยายน 15, 2009, 15:06:47 PM »
0
This example shows how to send a custom email at specific intervals from within a Delphi application. The application assumes the use of editable fields such as TEdit components to define the email properties. The advantage to this is that the programmer is able to easily code data validation into the application before executing Febooti Command line email for Windows. It is also possible to extend the application so that the user can schedule email sending.

SOLUTION:

1: After a new application is created in the Delphi IDE the following components should be added:

1.1: TEdit components for email fields such as Subject, Sender, Server, etc. The text from each TEdit component will be used for a specific field of the email. For instance SenderEdit.Text will represent the string that is used for the -SENDER argument in febootimail.
The text for each field can easily be validated during runtime for correctness such as the email address of the receiver containing a @ symbol. It is a good idea for these fields to contain pre-defined values or values which can be stored and retrieved, so they do not need to be typed every time the application is executed.

1.2: A TMemo component for the email body. Other text may also be appended to the string contained in the memo component or this string can be generated at run-time.

1.3: A TTimer component to schedule the task of sending the email. The interval property of the component must be set to a value of 60 seconds as an example. The enabled property should be set to true for the timer to function. This value can also be changed from another component such as a TButton during runtime, should the need arise for the user to start or stop the email schedule.

2: A format string should be defined to make the calling of Febooti Command line email for Windows more convenient. A format string can be defined in Delphi using the Format procedure. The format string required here can be defined as follows for a string variable named cmdStr:
cmdStr = Format('C:\febootimail -SERVER %s -FROM %s -TO %s -SUBJECT %s -MSG %S',
[serverEdit.text, fromEdit.text, toEdit.text, subjectEdit.text, messageMemo.text]);

The format procedure takes a string parameter that is modified using an array of format modifiers and returns the result as a formatted string. String modifiers are defined using %s. Each %s is then replaced with the text from the respective edit field.

3: The following code along with the code for the format string should be appended to the timer's OnTimer event:
uses ShellApi;
...
ShellExecute(Handle, 'open', cmdStr, nil, nil, SW_SHOWNORMAL);

The ShellExecute method is a native Windows method and specific to each version of Windows, thus it may return different error messages on different versions. The developer's documentation should be consulted for specifics of this method, however the above method should work with most versions of Windows.

Once the application has been successfully compiled and is running, provided the enabled property of the TTimer component has been set to true, it will automatically send email to the specified destination using Febooti Windows command line email utility.

doramon

  • บุคคลทั่วไป
Re: delphi
« ตอบกลับ #2 เมื่อ: กันยายน 15, 2009, 18:02:43 PM »
0
1. Place the Full Path to the database in Registry
2. Each time you start your app, read the Registry, "create" the ConnectionString and Open the ADOConnection.

This code is what I'm using:

Note: This is the OnCreate event handler of a data module. The RRead is a function that reads a string from the Registry is located below. RWrite writes a string to the Registry.

procedure Tdm.DataModuleCreate(Sender: TObject);
var
  DBPath : string;
  ADOConnSource : widestring;
begin
  //read path to db, try opening  - on error create OpenDialog and ask for db location
  DBPath:= RRead('DBPath','');
  if not FileExists(DBPath) then
  begin
    OpenDialog.Filter := 'MS Access (*.mdb)|*.mdb';
    OpenDialog.Options := [ofFileMustExist, ofPathMustExist , ofHideReadOnly, ofNoChangeDir, ofNoReadOnlyReturn, ofEnableSizing];
    if OpenDialog.Execute then
    begin
      DBPath :=  OpenDialog.FileName;
    end;
  end;

  ADOConnSource := 'Provider=Microsoft.Jet.OLEDB.4.0;'+
                   'User ID=Admin;Data Source=' +
                   DBPath +
                   ';Mode=Share Deny None;'+
                   'Persist Security Info=False;';

  ADOConn.ConnectionString := ADOConnSource;

  try
   ADOConn.Open;
   RWrite('DBPath', DBPath);
  except
    on E:Exception do
    begin
      ShowMessage(E.Message);
      Application.Terminate;
    end;
  end;

end;

 

 

function RRead(Name, DefaultValue: string):string;
var  Reg: TRegistry;
begin
 Reg := TRegistry.Create;
 result:='';
 with Reg do begin
  try
   RootKey := HKEY_CURRENT_USER;
   if OpenKey('\Software\ADP\', TRUE) then
    begin
      Result := ReadString(Name);
      if Result = '' then
      begin
        RWrite(Name, DefaultValue);
        Result:=DefaultValue
      end;
    end;
  Finally
   free;
  end; //try
end;//with
end;

 

function RWrite(Name, Value : string):boolean;
var  Reg: TRegistry;
begin
 Reg := TRegistry.Create;
 Result:=True;
 with Reg do begin
  try
   RootKey := HKEY_CURRENT_USER;
   if OpenKey('\Software\ADP\' , TRUE) then
    WriteString(Name, Value)
   else Result:=False;
  Finally
   free;
  end; //try
end;//with
end;

doramon

  • บุคคลทั่วไป
Re: delphi
« ตอบกลับ #3 เมื่อ: กันยายน 16, 2009, 21:57:01 PM »
0

{
  The CopyFile function copies an existing file to a new file.


 CopyFile(
  lpExistingFileName : PChar, // name of an existing file
  lpNewFileName : PChar,      // name of new file
  bFailIfExists : Boolean);   // operation if file exists

bFailIfExists:
  Specifies how this operation is to proceed if a file of the same name as
  that specified by lpNewFileName already exists.
  If this parameter is TRUE and the new file already exists, the function fails.
  If this parameter is FALSE and the new file already exists,
  the function overwrites the existing file and succeeds.
}

var
  fileSource, fileDest: string;
begin
  fileSource := 'C:\SourceFile.txt';
  fileDest := 'G:\DestFile.txt';
  CopyFile(PChar(fileSource), PChar(fileDest), False);
end;

ออฟไลน์ supakpu

  • Newbie
  • *
  • กระทู้: 27
  • คนบ้าแห่งโลกบาป
  • Respect: 0
    • ดูรายละเอียด
    • โรงพยาบาลสูงเนิน
Re: delphi
« ตอบกลับ #4 เมื่อ: เมษายน 17, 2011, 07:07:03 AM »
0
เค้าซื้อ หรือหา หรือ load
program delphi 7  กันที่ไหน

ผมต้องการลองทดสอบตัวเองก่อนตัดสินใจ อบรม delphi กับบริษัท นะครับ

ใครพอแนะนำได้ ช่วยด้วยน่ะครับ
supakpu@gmail.com
โรงพยาบาลสูงเนิน นครราชสีมา
HosXP ขึ้นระบบ โดย BMS ตุลาคม  2552

ออฟไลน์ thecoy

  • Hero Member
  • *****
  • กระทู้: 1,159
  • นักวิชาการคอมพิวเตอร์
  • Respect: 0
    • ดูรายละเอียด
Re: delphi
« ตอบกลับ #5 เมื่อ: เมษายน 17, 2011, 19:39:09 PM »
0
ขอบคุณมากครับ  ;D
โรงพยาบาลรัษฎา  ตรัง
CentOS 5.5  Ram  4  GB
HOSxP V.3.54.11.2 MySQL 5.1.30