Воскресенье, 06.07.2025, 17:05
Приветствую Вас Гость
Меню сайта


Копилка для дальнейшего развития ресурса.
 
Форма входа
Интересное
Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0

Программирование на Delphi.

Программирование

Главная » FAQ


uses
  ..., WinInet;

function GetInetFile ( const fileURL, FileName: string ): boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of byte;
  BufferLen: DWORD;
  f: file;
  sAppName: string;
begin
  Result := false;
  sAppName := ExtractFileName( Application.ExeName );
  hSession := InternetOpen( PChar( sAppName ),
  INTERNET_OPEN_TYPE_PRECONFIG,
  nil, nil, 0 );
  try
  hURL := InternetOpenURL( hSession, PChar( fileURL ), nil, 0, 0, 0 );
  try
  AssignFile( f, FileName );
  Rewrite( f, 1 );
  repeat
  InternetReadFile( hURL, @Buffer, SizeOf( Buffer), BufferLen );
  BlockWrite( f, Buffer, BufferLen )
  until BufferLen = 0;
  CloseFile( f );
  Result := true;
  finally
  InternetCloseHandle( hURL );
  end
  finally
  InternetCloseHandle( hSession );
  end
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  FileOnNet, LocalFileName: string;
begin
  // Полный путь к файлу
  FileOnNet := 'http://delphihelp.ucoz.ru/load/contacts.zip';
  // Имя, под которым файл будет сохранен
  LocalFileName:='File Downloaded From the Net.zip';
  if GetInetFile( FileOnNet, LocalFileName ) then
  ShowMessage( 'Download successful' )
  else
  ShowMessage( 'Error in file download' );
end;




uses
  ..., Consts;

function MessageDlgCtr(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; HelpCtx: Longint): integer;
begin
  with CreateMessageDialog( Msg, DlgType, Buttons ) do
  try
  HelpContext := HelpCtx;
  Left := Screen.ActiveForm.Left + ( Screen.ActiveForm.Width div 2 ) - ( Width div 2 );
  Top := Screen.ActiveForm.Top + ( Screen.ActiveForm.Height div 2 ) - ( Height div 2 );
  Result := ShowModal;
  finally
  Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlgCtr( 'Центрированный диалог', mtInformation, [mbOk], 0 );
end;




// Способ первый
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  s := ' Тестовая строка ';
  while Pos( ' ', s ) > 0 do
  Delete( s, Pos( ' ', s ), 1 );
  Edit1.Text := s;
end;

// Способ второй
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  s := ' Тестовая строка ';
  s := StringReplace( s, ' ', '', [rfReplaceAll] );
  Edit1.Text := s;
end;




procedure TForm1.Button3Click(Sender: TObject);
var
  s: string;
begin
  s := ' Тестовая строка ';
  if IsDelimiter( 'е', s, 5 ) then
  ShowMessage( 'Такая буква существует' )
  else
  ShowMessage( 'Такая буква не существует' );
end;




// Способ первый
var
  Form1: TForm1;
  Str: string = ' Добро пожаловать на сайт http://delphihelp.ucoz.ru ';

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Form1.Caption := Str;
  Str:= Copy( Str, 2, Length( Str )-1 ) + Str[1];
end;

// Способ второй
procedure TForm1.Timer1Timer(Sender: TObject);
var
  i: Integer;
  s: string;
begin
  s := Caption;
  for i := 1 to Length( s )-1 do
  s[i] := Caption[i+1];
  s[Length( s )] := Caption[1];
  Caption := s;
end;