Wolfgan 17 Junior Poster

Do you even know that this technology is COM? Because all objects VBA will work in Delphi. Accordingly, your task is to find the object you want to help and write code in Delphi. This is elementary. I can offer another option. There is a book which describes the work with the whole package of office: http://books.tr200.ru/v.php?id=40499
One problem - book in Russian I

Wolfgan 17 Junior Poster

Read the help! There because everything is written. You can not read or think? I gave you a link to an example of how to create an object. Next open the help for the VBA. The object model present. And even the examples are available. What else do you need? Just turn on the brain.

Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster

Before asking a question, you need to search. Perhaps someone has already done so on.
http://www.daniweb.com/code/snippet216536.html

Wolfgan 17 Junior Poster

Help reading have not tried it? DWORD is equivalent to LongWord.

uses
   MPlayer, MMSystem, Types;

or replace DWORD on LongWord. Everything works fine. I attach a file for example.

Wolfgan 17 Junior Poster

This problem for students. I do not see the code that you can not.
Formula for calculating a leap year is known to all.

Result := ((Year mod 4) = 0) and ((Year mod 100) <> 0) or ((Year mod 400) = 0);

Algorithm for computing is very simple.

const
  Days: array[1..12] of Byte = (31,28,31,30,31,30,31,31,30,31,30,31);
begin
     if (Month = 2) and IsLeapYear(Year) then
        Result := Days[Month]+1
     else
        Result := Days[Month];

Do not want to think for themselves? Then, and help you no sense. None who do not need experts do not know how to do the work yourself.

Wolfgan 17 Junior Poster
uses
   MPlayer, MMSystem;
 
 const
   MCI_SETAUDIO = $0873;
   MCI_DGV_SETAUDIO_VOLUME = $4002;
   MCI_DGV_SETAUDIO_ITEM = $00800000;
   MCI_DGV_SETAUDIO_VALUE = $01000000;
   MCI_DGV_STATUS_VOLUME = $4019;
 
 type
   MCI_DGV_SETAUDIO_PARMS = record
     dwCallback: DWORD;
     dwItem: DWORD;
     dwValue: DWORD;
     dwOver: DWORD;
     lpstrAlgorithm: PChar;
     lpstrQuality: PChar;
   end;
 
 type
   MCI_STATUS_PARMS = record
     dwCallback: DWORD;
     dwReturn: DWORD;
     dwItem: DWORD;
     dwTrack: DWORD;
   end;
 
 procedure SetMPVolume(MP: TMediaPlayer; Volume: Integer);
   { Volume: 0 - 1000 }
 var
   p: MCI_DGV_SETAUDIO_PARMS;
 begin
   { Volume: 0 - 1000 }
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
   p.dwValue := Volume;
   p.dwOver := 0;
   p.lpstrAlgorithm := nil;
   p.lpstrQuality := nil;
   mciSendCommand(MP.DeviceID, MCI_SETAUDIO,
     MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p));
 end;
 
 function GetMPVolume(MP: TMediaPlayer): Integer;
 var
    p: MCI_STATUS_PARMS;
 begin
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_STATUS_VOLUME;
   mciSendCommand(MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p));
   Result := p.dwReturn;
   { Volume: 0 - 1000 }
 end;
 
 // Example, Beispiel: 
 
procedure TForm1.Button1Click(Sender: TObject);
 begin
   SetMPVolume(MediaPlayer1, 500);
 end;
Wolfgan 17 Junior Poster
var
  i: integer;
  Source, Dest: string;
  Chars: array[32..127] of Char;
begin
  try
    Source := '';
    Dest := '';
    ReadLn(Source);
    for i := 1 to Length(Source) do
        if not (Chars[Ord(Source[i])] <> '') then
        begin
           Chars[Ord(Source[i])] := Source[i];
           Dest := Dest + Source[i];
        end;
    WriteLn(Dest);
end;
Wolfgan 17 Junior Poster
var
  Start: integer;
begin
  Start := GetTickCount;
   ......
   // your code
   ....
  ShowMessage(IntToStr(GetTickCount - Start)); // Msec
end;
Wolfgan 17 Junior Poster

It all depends on the application. It is often better to rewrite the entire program in another language. I have been programming in Delphi for 10 years. I say this based on experience. Any special language (Java or PHP or other) will cope with this task better. The code will be easier and shorter. There will be fewer mistakes. Of course at Delphi also it can be done.
Imagine if you were going to rest on the sea on the truck. You certainly will reach, but the car trip will be more enjoyable. :)

Wolfgan 17 Junior Poster

I understand. That's why I say it is better to write in Java. This language better solve any problem for the web. Better to spend time learning a new language, doing poorly performing interlayer.

Wolfgan 17 Junior Poster

Java...

Wolfgan 17 Junior Poster

bad XML file

Wolfgan 17 Junior Poster

Applicatin.Terminate;
Halt();

Wolfgan 17 Junior Poster

1. Use the function IOResult that would find the error code.
2.Try this:
CreateFile(pchar(filename),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);

Wolfgan 17 Junior Poster

Why do not you read the help?

In design time put Connection property to false. Then when you create a form need to call Open or set the Connected property to true.

ADOConnection1.Open;
ADODataSet.Open;

Wolfgan 17 Junior Poster

I think my code is much smaller. Less code = fewer bugs.
Сan just not give enter other characters. Put on the shape of TEdit. Create his handler OnKeyPress and paste the following code:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key in ['-','0','1','2','3','4','5','6','7','8','9',#8,DecimalSeparator] then
  begin
     if (Key = DecimalSeparator) and 
        (Pos(DecimalSeparator,(Sender as TEdit).Text) > 0) then
         Key := #0;
  end else
      Key := #0;
end;

You can assign one event to several TEdit.

Wolfgan 17 Junior Poster

Where is the code? What exactly does not work?

Wolfgan 17 Junior Poster

Possible. Just a little bit differently.

TBookName = string[20];
TPDFLink  = string[200];
BookLibrary = record
    AuthorName: String[20];
    BookName:   Array[1..20] of TBookName;
    PDFLink:    Array[1..20] of TPDFLink;
end;
Wolfgan 17 Junior Poster

Yes, as a way

procedure OnTimer(Sender: TObject)
begin
  WriteLn('The time has ended');
end;

var
  Timer: TTimer;
  TimerDelay: integer;
begin  
  Randomize;
  TimerDelay = 10 + Random(50);
  Timer := TTimer.Create(self);
  Timer.Interval := TimerDelay;
  Timer.OnTimer := OnTimer;
end;
Wolfgan 17 Junior Poster

To do this, use any database. If it is not possible, then recommend the use of "linked list".
http://en.wikipedia.org/wiki/Linked_list

Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster

Try Indy. TidHTTP

Wolfgan 17 Junior Poster
for i:=0 to MainForm.MDIChildCount-1 do
  MainForm.MDIChildren[i].Show;
Wolfgan 17 Junior Poster

for Delphi 2009

uses
 Winsock;

const
  WINSOCK_VERSION = $0101;

function GetIPAddress(name: AnsiString): string;
const WSVer = $101;
var
  wsaData: TWSAData;
  P: PHostEnt;
begin
  Result := '';
  if WSAStartup(WSVer, wsaData) = 0 then begin
   begin
      P := GetHostByName(PAnsiChar(name));
      if P <> nil then Result := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
    end;
    WSACleanup;
  end;
end;

for Delphi 7

uses
 Winsock;

const
  WINSOCK_VERSION = $0101;

function GetIPAddress(name: String): string;
const WSVer = $101;
var
  wsaData: TWSAData;
  P: PHostEnt;
begin
  Result := '';
  if WSAStartup(WSVer, wsaData) = 0 then begin
   begin
      P := GetHostByName(PChar(name));
      if P <> nil then Result := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
    end;
    WSACleanup;
  end;
end;
Wolfgan 17 Junior Poster

Menu: Project->Options->Forms. Drgag&Drop order.
or
Menu: Project->View source.

Wolfgan 17 Junior Poster
var
  inFile, outFile: TextFile;
  curLine: string;
  rowCount: integer;
begin
  AssignFile(inFile,'inFilename.out');
  Reset(inFile);
  AssignFile(outFile,'outFilename.txt');
  Reset(outFile);
  try
    while not Eof(inFile) do
    begin
      ReadLn(inFile,curLine);
      if Pos('state summary:', curLine) > 0 then
      begin
         rowCount := 0;
         repeat
           if Eof(inFile) then Break;
           ReadLn(inFile, curLine);
           WriteLn(outFile,curLine);
           inc(rowCount);
         until rowCount = 10;
      end;
    end;

  finally
    CloseFile(inFile);
    CloseFile(outFile)
  end;
Wolfgan 17 Junior Poster
var
  inFile, outFile: TStringList;
  Row, rowCount: integer;
begin
  inFile := TStringList.Create;
  try
    Row := 0;
    inFile.LoadFromFile('inFilename.out');
    while Row < inFile.Count do
    begin
      if Pos('state summary:',inFile.Strings[Row]) > 0 then
      begin
         inc(Row);
         outFile := TStringList.Create;
         try
           rowCount := 0;
           while (rowCount < 10) do
           begin
             outFile.Add(inFile.Strings[Row]);
             inc(Row);
             inc(rowCount);
             if Row = inFile.Count then Break;
           end;
           outFile.SaveToFile('outFilename.txt');
         finally
           outFile.Free;
         end;
      end else
          inc(Row);
    end;
  finally
    inFile.Free;
  end;
Wolfgan 17 Junior Poster

Look in the direction of the INI-file - TInifile.

Wolfgan 17 Junior Poster

What is the problem? Do not use such functions. The file name can be formed so:

for i := 1 to a do
     name := Format('file_%d.txt',[i]);
.........
  for i := 1 to a do
     name := 'file_' + IntToStr(i) + '.txt';

 /// add current path

name := ExtractFilePath(ParamStr(0)) + name;
Wolfgan 17 Junior Poster

Pascal
procedure WriteComponentResFile(const FileName: string; Instance: TComponent);
File
Classes
Description
Use WriteComponentResFile to save the component specified by the Instance parameter to the specified file, storing it in a resource-file format.

To read a component written with WriteComponentResFile, call ReadComponentResFile.

Wolfgan 17 Junior Poster
with TStringList.Create do
  try
    LoadFromFile('a.txt');
    SaveToFile('b.txt');
  finally
    Free;
  end;

or WinAPI
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists );

Wolfgan 17 Junior Poster

It Delphi function. Tests if a specified file exists.
File: SysUtils
Description:
FileExists returns true if the file specified by FileName exists. If the file does not exist, FileExists returns false.

errCount := 0;
   for i := 1 to a do
   try
     name := Format('file_%d.txt',[i]);
     assign (f,name); (include variable into file name)
     reset (f);
     read (something unimportant here);
     close (f);
   except
     inc(errCount);
   end;

   id errCount <> 0 then
      ........
Wolfgan 17 Junior Poster
for i := 1 to a do
   begin
     name := Format('file_%d.txt',[i]);
     if FileExists(name) then
     begin
       assign (f,name); (include variable into file name)
       reset (f);
       read (something unimportant here);
       close (f);
     end;
   end;
Wolfgan 17 Junior Poster

Then it is better to use INI files. But this is not the best option.

var
  i,j: integer;
begin
  with TIniFile.Create(ExtractFilePath(ParamStr(0))+'Filename.txt') do
  try
    for i := 0 to self.ControlCount-1 do
      if (self.Controls[i] is TEdit) then
          WriteString(self.Controls[i].Name,'Value',(self.Controls[i] as TEdit).Text)
      else
      if (self.Controls[i] is TMemo) then
         for j := 0 to (self.Controls[i] as TMemo).Lines.Count - 1 do
           WriteString(self.Controls[i].Name,'Line'+intToStr(j),(self.Controls[i] as TMemo).Lines[j]);
  finally
    Free;
  end;
var
  i,j,idx: integer;
  StrList: TStringList;
begin
  with TIniFile.Create(ExtractFilePath(ParamStr(0))+'Filename.txt') do
  try
    for i := 0 to self.ControlCount-1 do
     if (self.Controls[i] is TEdit) then
        (self.Controls[i] as TEdit).Text := ReadString(self.Controls[i].Name,'Value','')
     else
     if (self.Controls[i] is TMemo) then
     begin
       StrList := TStringList.Create;
       try
         ReadSectionValues(self.Controls[i].Name,StrList);
         (self.Controls[i] as TMemo).Clear;
         for j := 0 to StrList.Count - 1 do
           (self.Controls[i] as TMemo).Lines.Add(StrList.ValueFromIndex[j]);
       finally
         StrList.Free;
       end;
     end;
  finally
    Free;
  end;
Wolfgan 17 Junior Poster

Yes. Easy.

Save:

procedure TForm1.SaveButtonClick(Sender: TObject);
var
  i: integer;
begin
  with TStringList.Create do
  try
    for i := 0 to self.ControlCount-1 do
      if (self.Controls[i] is TEdit) then
          Add(self.Controls[i].Name+'='+(self.Controls[i] as TEdit).Text);
    SaveToFile('Filename.txt');
  finally
    Free;
  end;
end;

load:

procedure TForm1.LoadButtonClick(Sender: TObject);
var
  i,idx: integer;
begin
  with TStringList.Create do
  try
    LoadFromFile('Filename.txt');
    for i := 0 to self.ControlCount-1 do
    begin
      idx := IndexOfName(self.Controls[i].Name);
      if idx <> -1 then
         (self.Controls[i] as TEdit).Text := ValueFromIndex[idx];
    end;
  finally
    Free;
  end;
end;
Wolfgan 17 Junior Poster

I do not know English. It will be difficult to explain. It is not difficult. I recommend to use SOAP. There will be less rework. See attached example. Unfortunately I have documentation in Russian only.

Wolfgan 17 Junior Poster
Wolfgan 17 Junior Poster

Bitmap to Icon:
We need to create two bitmap: bitmap-mask ("AND" bitmap) and bitmap-image (XOR bitmap). Then transmit descriptors "AND" and "XOR" bitmap-s API functions CreateIconIndirect ():

procedure TForm1.Button1Click(Sender: TObject);
var
  IconSizeX: integer;
  IconSizeY: integer;
  AndMask: TBitmap;
  XOrMask: TBitmap;
  IconInfo: TIconInfo;
  Icon: TIcon;
begin
  {Get the icon size}
  IconSizeX := GetSystemMetrics(SM_CXICON);
  IconSizeY := GetSystemMetrics(SM_CYICON);
  {Create the "And" mask}
  AndMask := TBitmap.Create;
  AndMask.Monochrome := true;
  AndMask.Width := IconSizeX;
  AndMask.Height := IconSizeY;
  {Draw on the "And" mask}
  AndMask.Canvas.Brush.Color := clWhite;
  AndMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
  AndMask.Canvas.Brush.Color := clBlack;
  AndMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4);
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 2, IconSizeY, AndMask);
  {Create the "XOr" mask}
  XOrMask := TBitmap.Create;
  XOrMask.Width := IconSizeX;
  XOrMask.Height := IconSizeY;
  {Draw on the "XOr" mask}
  XOrMask.Canvas.Brush.Color := ClBlack;
  XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
  XOrMask.Canvas.Pen.Color := clRed;
  XOrMask.Canvas.Brush.Color := clRed;
  XOrMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4);
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 4, IconSizeY, XOrMask);
  {Create a icon}
  Icon := TIcon.Create;
  IconInfo.fIcon := true;
  IconInfo.xHotspot := 0;
  IconInfo.yHotspot := 0;
  IconInfo.hbmMask := AndMask.Handle;
  IconInfo.hbmColor := XOrMask.Handle;
  Icon.Handle := CreateIconIndirect(IconInfo);
  {Destroy the temporary bitmaps}
  AndMask.Free;
  XOrMask.Free;
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 6, IconSizeY, Icon);
  {Assign the application icon}
  Application.Icon := Icon;
  {Force a repaint}
  InvalidateRect(Application.Handle, nil, true);
  {Free the icon}
  Icon.Free;
end;
Wolfgan 17 Junior Poster

1.Make cursor in cursor editor (hand.cur).
2.Make text file "cursors.rc": HAND CURSOR HAND.CUR
3.Compile: "C:\Program Files\CodeGear\RAD Studio\6.0\bin\brcc32.exe" cursor.rc
4.In program:

const
  crHand  = 10;
....
implementation
{$R Cursor.res}
.....
procedure TForm1.Create(Owner: TObject);
begin
  Screen.Cursors[crHand]  := LoadCursor(hInstance,'HAND');
end;
...
uses:
  Screen.Cursor := crHand;
Wolfgan 17 Junior Poster

IntraWeb

Wolfgan 17 Junior Poster

P.S.: sorry for bad english

Wolfgan 17 Junior Poster

What's the problem?
Look for the line 13: TObject(pe32.th32ProcessID) - This process id.
Do it like this:

procedure TMainForm.StopProcess(AHandle: THandle);
var
  Res: THandle;
begin
  res := OpenProcess(PROCESS_TERMINATE, False, AHandle);
  if Res <> 0 then
     TerminateProcess(res, NO_ERROR);
end;

and next:

StopProcess(integer(ProcessList.Objects[index]));

This is the code from a real program. GetProcessList called from additional Thread and passes the process ID in the main thread. Function StopProcess belongs to the main form window and called on pressing the button.

Maybe you need something like this:

res := OpenProcess(PROCESS_TERMINATE, False, pe32.th32ProcessID);
  if Res <> 0 then
    AList.AddObject(pe32.szExeFile,TObject(res));
Wolfgan 17 Junior Poster

Avoid cycles. Can simplify:

Memo1.Lines.Add(ListBox1.Items.Strings[ListBox1.ItemIndex]);
Wolfgan 17 Junior Poster

Try it:

function TProcessControl.GetProcessList(AList: TStrings): Boolean;
var
  hSnapshoot: THandle;
  pe32: TProcessEntry32;
begin
  Result := true;
  AList.Clear;
  hSnapshoot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if (hSnapshoot <> -1) then begin
    pe32.dwSize := SizeOf(TProcessEntry32);
    if (Process32First(hSnapshoot, pe32)) then
      repeat
        AList.AddObject(pe32.szExeFile,TObject(pe32.th32ProcessID));
      until not Process32Next(hSnapshoot, pe32);
      CloseHandle (hSnapshoot);
  end else
      Result := False;
end;

Example:

procedure ShowProcessInfo;
var
  i: integer;
  ProcessList: TStringList;
behin
  ProcessList: TStringList;
  ProcessList := TStringList.Create;
  ProcessList.Sorted := true;
  ProcessList.Duplicates := dupIgnore;
  try
    if GetProcessList(ProcessList) then
    begin
       for i:=0 to ProcessList.Count-1 do
        WriteLn(ProcessList.Strings[i], integer(ProcessList.Objects[i]));
    end;
  finally
    ProcessList.Free;
  end;
Wolfgan 17 Junior Poster

Try StartTransaction and CommitTransaction

Wolfgan 17 Junior Poster

Maybe this will help http://www.alphaskins.com/

Wolfgan 17 Junior Poster

I'm sorry, do not speak English. View property Anchor

Wolfgan 17 Junior Poster

for disable input other digit, for TEdit.OnKeyPress:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['1','2','3']) then Key := #0;
end;

or, for check range:

function ValueInRange(const Val: string; const Min,Max: integer): Boolean;
begin
  Result := (Trim(Val) <> '') and ((Val >= IntToStr(Min)) and (Val <= IntToStr(Max)));
end;
Wolfgan 17 Junior Poster
procedure TForm1.FormResize(Sender: TObject);
begin
  Panel1.Width  := (ClientWidth div 100) * 80;
  Panel1.Height := (ClientHeight div 100) * 80;
  Panel1.Left   := (ClientWidth div 2) - (Panel1.Width div 2);
  Panel1.Top    := (ClientHeight div 2) - (Panel1.Height div 2);

  Image1.Width  := (Panel1.Width div 100) * 80;
  Image1.Height := (Panel1.Height div 100) * 80;
  Image1.Left   := (Panel1.Width div 2) - (Image1.Width div 2);
  Image1.Top    := (Panel1.Height div 2) - (Image1.Height div 2);
end;