Este documento, originado do departamento de ciência da computação da universidade tiradentes, aborda conceitos relacionados a formulários, componentes e unidades em aplicações, com foco na formatação de data e hora utilizando o delphi. Fornece informações sobre especificadores de formato, como c, d, ddd, mmmm, yy, hh, ss e tt, além de explicar como formatar valores positivos, negativos e zero.
Baixe Formulários, Componentes e Unidades em Aplicações: Formatação de Data e Hora no Delphi e outras Notas de estudo em PDF para Automação, somente na Docsity!
UNIVERSIDADE TIRADENTES
DEPARTAMENTO DE CIÊNCIA DA COMPUTAÇÃO
Prof. José Maria Rodrigues Santos Júnior
Linguagem Técnica de Programação
DELPHI
Básico
Aracaju 4 de fevereiro de 1997
Programação Windows
DELPHI
Características do Delphi
Ambiente de Desenvolvimento Delphi
Desenvolvendo Aplicativos
Principais Procedimentos e Funções Pré-definidas
Componentes - Propriedades, Eventos e Métodos
Aplicações MDI
Use de Modelos e Experts
Os objetos
Application
Screen
Printer
Canvas
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
Projeto de Interface
Padronização
Tomar como base as aplicações existentes, principalmente as da Microsoft.
Utilizar menus com as opções Arquivo, Editar, Janela e Ajuda.
Usar botões de acesso rápido.
Utilizar teclas de atalho.
Enfatizar imagens.
Esquecer a programação DOS
Não utilizar múltiplos níveis de menu.
Não exagerar em cores diferentes.
Utilizar a tecla TAB para passar de um campo para outro.
Utilizar a tecla ENTER ou um botão para executar ações.
Simplicidade
Procurar facilidade de uso.
Permitir liberdade de ação.
Permitir diferentes maneiras de se alcançar o mesmo resultado.
Procurar as soluções mais intuitivas.
Procurar adotar os símbolos que o usuário já esteja acostumado.
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
DELPHI
Características do Delphi
Gera um executável verdadeiro, independente de run-time.
Utiliza um dialeto da linguagem Object Pascal para escrever os procedimentos do programa.
Utiliza o processo de desenvolvimento Two-Way , que permite tanto escrever o código em Object Pascal
gerando os objetos visuais, como utilizar os métodos visuais gerando código em Object Pascal.
Os componentes são definidos como objetos, o que permite a herança.
Permite a criação de novos componentes na própria linguagem.
Possui acesso facilitado a banco de dados.
Possui ambiente de depuração integrado.
Possui componenete para a internet
Características da Programação Delphi
Um programa Delphi é uma estrutura de aplicativo
Orientada ao desenho de formulários ou janelas.
Interface com usuário feita através de componentes
Contém um conjunto de controles pré-desenvolvidos que dão acesso às características do sistema.
Os componentes são objetos
Cada controle ou componente possui propriedades, métodos e pode responder a eventos.
As propriedades podem ter seus valores definidos em tempo de desenvolvimento e alterados em tempo de
execução.
Os eventos são as mensagens que cada componente pode responder, tendo associado a eles um procedimento
de evento.
Elementos da Programação Delphi :
Elemento Descrição
Formulário (Form) É uma janela, elemento básico onde agrupamos os componentes para formar a
interface com o usuário.
Unidade (Unit) Arquivo que contém código em object pascal. Para cada formulário existe uma
unidades associada
Componente Objetos utilizados para a construção das nossas aplicações (projeto).
Propriedade Representam os atributos dos componentes
Método Procedimento ou função própria do objeto.
Evento Representam a capacidade de resposta dos componentes aos estímulos
Processador de Evento Procedimento responsável por responder a determinado evento
Projeto (Project) Conjunto de formulários, componentes e unidades que compõem uma aplicação
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
Desenvolvendo Aplicativos
Manipulando Componentes:
Acrescentando
Selecionando
Movendo
Sobrepondo
Alinhando
Redimensionando
Cortando, Copiando e Colando
Criando Ordem de Acesso (Tab Order)
Fixando
Alterando Propriedades dos Componentes em Tempo de Projeto
1. Selecione o Componente, depois mude a propriedade no Object Inspector
Editor de Propriedade : Simples, Lista Suspensa, Caixa de Dialogo e Propriedades Aninhadas
Escrevendo Procedimentos de Eventos
Selecione o Componente, escolha, na Object Inspector, o evento a ser respondido e Click-Duplo na coluna
direita, e então escreva o procedimento
Alterando Propriedades em Tempo de execução
Componente.Propriedade := NovoValor
OBS: Quando a propriedade for aninhada use
Componente.Propriedade := Componente.Propriedade
F 0
B 1 [ConstanteDaPropriedade]
Utilizando métodos
Componente.Método
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
begin
ADate := StrToDate(Edit1.Text);
Label1.Caption := 'Day ' + IntToStr(DayOfWeek(ADate)) + ' of the week';
end;
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
Quebra os valores especificados no parâmetro Date em Year, Month e Day.
procedure TForm1.Button1Click(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
Quebra os valores especificados em Time nos par6ametros Hour, Min, Sec e MSec.
procedure TForm1.Button1Click(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
Remove a substring de Count caracters da string S partir da posição Index
var
s: string;
begin
s := 'Honest Abe Lincoln';
Delete(s,8,4);
Canvas.TextOut(10, 10, s); { 'Honest Lincoln' }
end;
function DeleteFile(const FileName: string): Boolean;
Apaga o arquivo FileName do disco. Se o arquivo não puder ser apagado a função retorna False.
DeleteFile('DELETE.ME');
function DirectoryExists(Name: string): Boolean;
Verifica se Name diretorio existe
function DiskFree(Drive: Byte): Integer;
Retorna o número de bytes livre no driver especificado em Drive.
Onde : 0 = Corrente, 1 = A, 2 = B,...
DiskFree retorna –1 se o driver for inválido
var
S: string;
begin
S := IntToStr(DiskFree(0) div 1024) + ' Kbytes free.';
Canvas.TextOut(10, 10, S);
end;
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
function DiskSize(Drive: Byte): Integer;
Retorna o tamanho em bytes do driver especificado.
Onde : 0 = Corrente, 1 = A, 2 = B,...
DiskFree retorna –1 se o driver for inválido
var
S: string;
begin
S := IntToStr(DiskSize(0) div 1024) + ' Kbytes capacity.';
Canvas.TextOut(10, 10, S);
end;
function EncodeDate(Year, Month, Day: Word): TDateTime;
Retorna uma Data formada por Year, Month e Day
procedure TForm1.Button1Click(Sender: TObject);
var
MyDate: TDateTime;
begin
MyDate := EncodeDate(83, 12, 31);
Label1.Caption := DateToStr(MyDate);
end;
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
Retorna a Hora formada por Hour, Min, Sec e MSec
procedure TForm1.Button1Click(Sender: TObject);
var
MyTime: TDateTime;
begin
MyTime := EncodeTime(0, 45, 45, 7);
Label1.Caption := TimeToStr(MyTime);
end;
function ExtractFileDir(const FileName: string): string;
Retorna o diretório adequado para ser passado para as funções CreateDir, GetCurrentDir, RemoveDir e SetCurrentDir.
O resultado da função é uma string vazia se FileName não contiver um drive e um caminho.
function ExtractFileDrive(const FileName: string): string;
Retorna uma string contendo o drive do path de um arquivo.
function ExtractFileExt(const FileName: string): string;
Retorna a extensão do arquivo FileName
function ExtractFileName(const FileName: string): string;
function ExtractFilePath(const FileName: string): string;
Retorna o Path de um arquivo
ChDir(ExtractFilePath(FileName));
function FileAge(const FileName: string): Integer;
Retorna a data e a hora de um arquivo num valor que pode ser convertido para TDateTime através da função FileDateToDateTime.
Retorna –1 se o arquivo não existir
function FileExists(const FileName: string): Boolean;
Retorna verdade se o arquivo existir
if FileExists(FileName) then
if MsgBox('Do you really want to delete ' + ExtractFileName(FileName)
+ '?'), []) = IDYes then DeleteFile(FileName);
function FileSize(var F): Integer;
Retorna o tamanho de um arquivo, para usar FileSize o arquivo deve esta aberto. Se o arquivo estiver vazio FileSize(F) retorna 0.
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
yyyy Displays the year as a four-digit number (0000-9999).
h Displays the hour without a leading zero (0-23).
hh Displays the hour with a leading zero (00-23).
n Displays the minute without a leading zero (0-59).
nn Displays the minute with a leading zero (00-59).
s Displays the second without a leading zero (0-59).
ss Displays the second with a leading zero (00-59).
t Displays the time using the format given by the ShortTimeFormat global variable.
tt Displays the time using the format given by the LongTimeFormat global variable.
am/pm Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any
hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
a/p Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour
after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
ampm Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable
for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.
/ Displays the date separator character given by the DateSeparator global variable.
: Displays the time separator character given by the TimeSeparator global variable.
'xx'/"xx" Characters enclosed in single or double quotes are displayed as-is, and do not affect formatting.
Format specifiers may be written in upper case as well as in lower case letters--both produce the same result.
If the string given by the Format parameter is empty, the date and time value is formatted as if a 'c' format specifier had been given.
S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
function FormatFloat(const Format: string; Value: Extended): string;
Transforma um Float numa string usando a formatação contida em Format
Os especificadores de formato abaixo são válidos
Specifier Represents
0 Digit place holder. If the value being formatted has a digit in the position where the '0' appears in the format string, then
that digit is copied to the output string. Otherwise, a '0' is stored in that position in the output string.
# Digit placeholder. If the value being formatted has a digit in the position where the '#' appears in the format string, then
that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string.
. Decimal point. The first '.' character in the format string determines the location of the decimal separator in the formatted
value; any additional '.' characters are ignored. The actual character used as a the decimal separator in the output string is
determined by the DecimalSeparator global variable. The default value of DecimalSeparator is specified in the Number
Format of the International section in the Windows Control Panel.
, Thousand separator. If the format string contains one or more ',' characters, the output will have thousand separators
inserted between each group of three digits to the left of the decimal point. The placement and number of ',' characters in
the format string does not affect the output, except to indicate that thousand separators are wanted. The actual character
used as a the thousand separator in the output is determined by the ThousandSeparator global variable. The default value
of ThousandSeparator is specified in the Number Format of the International section in the Windows Control Panel.
E+ Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-' are contained in the format string, the number is formatted
using scientific notation. A group of up to four '0' characters can immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine
the minimum number of digits in the exponent. The 'E+' and 'e+' formats cause a plus sign to be output for positive
exponents and a minus sign to be output for negative exponents. The 'E-' and 'e-' formats output a sign character only for
negative exponents.
'xx'/"xx"Characters enclosed in single or double quotes are output as-is, and do not affect formatting.
; Separates sections for positive, negative, and zero numbers in the format string.
The locations of the leftmost '0' before the decimal point in the format string and the rightmost '0' after the decimal point in the
format string determine the range of digits that are always present in the output string.
The number being formatted is always rounded to as many decimal places as there are digit placeholders ('0' or '#') to the right of
the decimal point. If the format string contains no decimal point, the value being formatted is rounded to the nearest whole number.
If the number being formatted has more digits to the left of the decimal separator than there are digit placeholders to the left of the
'.' character in the format string, the extra digits are output before the first digit placeholder.
To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections
separated by semicolons.
One section: The format string applies to all values.
Two sections: The first section applies to positive values and zeros, and the second section applies to negative values.
Three sections: The first section applies to positive values, the second applies to negative values, and the third applies to
zeros.
If the section for negative values or the section for zero values is empty, that is if there is nothing between the semicolons that
delimit the section, the section for positive values is used instead.
If the section for positive values is empty, or if the entire format string is empty, the value is formatted using general floating-point
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
formatting with 15 significant digits, corresponding to a call to FloatToStrF with the ffGeneral format. General floating-point
formatting is also used if the value has more than 18 digits to the left of the decimal point and the format string does not specify
scientific notation.
#,##0.00;;Zero 1,234.00 -1,234.00 0.50 Zero
0.000E+00 1.234E+03 -1.234E+03 5.000E-01 0.000E+
#.###E-0 1.234E3 -1.234E3 5E-1 0E
function Frac(X: Real): Real;
Retorna a parte fracional do parâmetro X
var
R: Real;
begin
R := Frac(123.456); { 0.456 }
R := Frac(-123.456); { -0.456 }
end;
function GetCurrentDir: string;
Retorna uma string contendo o diretório corrente
procedure GetDir(D: Byte; var S: string);
Rerorna o diretório corrente do driver especificado.
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
Exibe uma Caixa de Mensagem e obtem uma resposta do usuário.
Onde
Msg : Mensagem
AType : Tipo da caixa de mensagem
Value Meaning
mtWarning A message box containing a yellow exclamation point symbol.
mtError A message box containing a red stop sign.
mtInformation A message box containing a blue "i".
mtConfirmation A message box containing a green question mark.
mtCustom A message box with no bitmap. The caption of the message box is the name of the application's executable file.
AButtons : Quais botões aparecerão na caixa de mensagem
Value Meaning
mbYes A button with the text 'Yes' on its face
mbNo A button with the text 'No' on its face
mbOK A button with the text 'OK' on its face
mbCancel A button with the text 'Cancel' on its face
mbHelp A button with the text 'Help' on its face
mbAbort A button with the text 'Abort' on its face
mbRetry A button with the text 'Retry' on its face
mbIgnore A button with the text 'Ignore' on its face
mbAll A button with the text 'All' on its face
mbYesNoCancel Puts Yes, No, and Cancel buttons in the message box
mbOkCancel Puts t OK and Cancel buttons in the message box
mbAbortRetryIgnore Puts Abort, Retry, and Ignore buttons in the message box
MessageDlg returns the value of the button the user selected. These are the possible return values:
Return values
mrNone mrAbort mrYes
mrOk mrRetry mrNo
mrCancel mrIgnore mrAll
procedure TForm1.Button1Click(Sender: TObject);
begin
if MessageDlg('Welcome to my Object Pascal application. Exit now?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
MessageDlg('Exiting the Object Pascal application.', mtInformation,
[mbOk], 0);
Close;
end;
end;
function MessageDlgPos(const Msg: string; AType: TMsgDlgType;
Semelhante a MessageDlg exceto por permitir indicar a posição na qual a janela será exibida
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200);
end;
function MinIntValue(const Data: array of Integer): Integer;
Retorna o menor inteiro do vetor
function MinValue(const Data: array of Double): Double;
Retorna o menor valor de um vetor
procedure MkDir(S: string);
Cria um novo diretório
uses Dialogs;
begin
{$I-}
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
Label1.Caption := 'The date and time is ' + Str(Now);
end;
function Ord(X): Longint;
Retorna a ordem de um valor ordinal
uses Dialogs;
type
Colors = (RED,BLUE,GREEN);
var
S: string;
begin
S := 'BLUE has an ordinal value of ' + IntToStr(Ord(BLUE)) + #13#10;
S := 'The ASCII code for "c" is ' + IntToStr(Ord('c')) + ' decimal';
MessageDlg(S, mtInformation, [mbOk], 0);
end;
function Pi: Extended;
Retorna o valor de PI
function Pos(Substr: string; S: string): Integer;
Procura por uma sub-string numa string e retorna a posição da primeira ocorrência ou zero se não encontrou
var S: string;
begin
S := ' 123.5';
{ Convert spaces to zeroes }
while Pos(' ', S) > 0 do
S[Pos(' ', S)] := '0';
end;
function Power(Base, Exponent: Extended): Extended;
Potência
function Pred(X);
Retorna o predecessor de um ordinal
uses Dialogs;
type
Colors = (RED,BLUE,GREEN);
var
S: string;
begin
S := 'The predecessor of 5 is ' + IntToStr(Pred(5)) + #13#10;
S := S + 'The successor of 10 is ' + IntToStr(Succ(10)) + #13#10;
if Succ(RED) = BLUE then
S := S + 'In the type Colors, RED is the predecessor of BLUE.';
MessageDlg(S, mtInformation, [mbOk], 0);
end;
function Random [ ( Range: Integer) ];
Retorna um valor Randômico
0 <= X < Range.
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
diretório escolhido é retonado no mesmo Diretório (Directory). O valor do diretório corrente não é alterado
These are the possible values that can be added to the Options set:
Value Meaning
sdAllowCreate An edit box appears to allow the user to type in the name of a directory that does not exist. This option does not
create a directory, but the application can access the Directory parameter to create the directory selected if
desired.
sdPerformCreate Used only when Options contains sdAllowCreate. If the user enters a directory name that does not exist,
SelectDirectory creates it.
sdPrompt Used when Options contains sdAllowCreate. Displays a message box that informs the user when the entered
directory does not exist and asks if the directory should be created. If the user chooses OK, the directory is
created if Options contains sdPerformCreate. If Options does not contain sdPerformCreate, the directory is not
created: the application should create it when SelectDirectory returns.
The function returns True if the user selected a directory and chose OK, and False if the user chose Cancel or closed the dialog box
without selecting a directory.
This example uses a button on a form. When the user clicks the button, a Select Directory dialog box appears.
The current directory displayed in the dialog box is C:\MYDIR. The user can select a directory from the
directory list, or enter a new directory in the edit box. If the user enters a new directory, a message box
asks the user if the directory should be created. If the user chooses Yes, the directory is created. If the
user chooses No, the message box goes away without creatubg the directory. The name of the directory the user
selects appears as the caption of the label:
uses FileCtrl;
procedure TForm1.Button1Click(Sender: TObject);
var
Dir: string;
begin
Dir := 'C:\MYDIR';
if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt]) then
Label1.Caption := Dir;
end;
function SetCurrentDir(const Dir: string): Boolean;
Torna o Dir o diretório corrente e retorna o sucesso da operação
function StringOfChar(Ch: Char; Count: Integer): string;
Retorna uma string contendo Count caracters Ch
S := StringOfChar('A', 10);
{sets S to the string 'AAAAAAAAAA'}
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E
function StrToDate(const S: string): TDateTime;
Converte uma string em data
procedure TForm1.Button1Click(Sender: TObject);
var
ADate: TDateTime;
begin
ADate := StrToDate(Edit1.Text);
Label1.Caption := DateToStr(ADate);
end;
function StrToDateTime(const S: string): TDateTime;
Convrete uma string para o formato DateTime
procedure TForm1.Button1Click(Sender: TObject);
var
ADateAndTime: TDateTime;
begin
ADateAndTime := StrToDateTime(Edit1.Text);
Label1.Caption := DateTimeToStr(ADateAndTime);
end;
function StrToFloat(const S: string): Extended;
Converte uma string num Float
function StrToInt(const S: string): Integer;
Converte uma string num inteiro
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
I: Integer;
begin
S := '22467';
I := StrToInt(S);
Inc(I);
Edit1.Text := IntToStr(I);
end;
function StrToTime(const S: string): TDateTime;
Converte uma string em hora
procedure TForm1.Button1Click(Sender: TObject);
var
ATime: TDateTime;
begin
ATime := StrToTime(Edit1.Text);
Label1.Caption := TimeToStr(ATime);
end;
function Succ(X);
Retorna o sucessor de um ordinal
uses Dialogs;
type
Colors = (RED,BLUE,GREEN);
var
S: string;
begin
S := 'The predecessor of 5 is ' + IntToStr(Pred(5)) + #13#10;
S := S + 'The successor of 10 is ' + IntToStr(Succ(10)) + #13#10;
if Succ(RED) = BLUE then
S := S + 'In the type Colors, RED is the predecessor of BLUE.';
MessageDlg(S, mtInformation, [mbOk], 0);
end;
function Sum(const Data: array of Double): Extended register;
Calcula a soma de dos elementos de um vetor
F 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B EF 0 B E