Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Question:
I want to disable keyboard shortcut for paste!

Answer:
No problem, I have example for disabling CTL-V for TMemo.
Here it is ...

{
Prevent users from pasting text in your Memo.
}

uses Clipbrd;
...

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ((Key=Ord('V'))and(ssCtrl in Shift)) then
begin
Clipboard.Clear;
Memo1.SelText:='Delphi tricks rules!';
Key:=0;
end;
end;

Question: How to Check if a String is numeric?

Answer:
If you mean string is 1,2,3,4 ....0 in string mode.
Here the code:

function IsStrANumber(const S: string): Boolean;
var
P: PChar;
begin
P := PChar(S);
Result := False;
while P^ <> #0 do
begin
if not (P^ in ['0'..'9']) then Exit;
Inc(P);
end;
Result := True;
end;

Question:
How to separate number wih thousand separator?

Answer:
Here the code, its totally easy ..
The output sent to label1.Caption, you may replace to the other component.

function AddThousandSeparator(S: string; Chr: Char): string;
var
I: Integer;
begin
Result := S;
I := Length(S) - 2;
while I > 1 do
begin
Insert(Chr, Result, I);
I := I - 3;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := AddThousandSeparator('400500210', '''');
// -- 400'500'210
end;
label1.Caption := FormatFloat('#,###,###.###', 23453452);

Question:
I wish have a program which make Highlight HTML-Tags in TRichEdit.

Answer:
Here it is .... :p

procedure HTMLSyntax(RichEdit: TRichEdit; TextCol, TagCol, DopCol: TColor);
var
i, iDop: Integer;
s: string;
Col: TColor;
isTag, isDop: Boolean;
begin
iDop := 0;
isDop := False;
isTag := False;
Col := TextCol;
RichEdit.SetFocus;
for i := 0 to Length(RichEdit.Text) do
begin
RichEdit.SelStart := i;
RichEdit.SelLength := 1;
s := RichEdit.SelText;
if (s = '<') or (s = '{') then isTag := True;
if isTag then
if (s = '"') then
if not isDop then
begin
iDop := 1;
isDop := True;
end
else
isDop := False;
if isTag then
if isDop then
begin
if iDop <> 1 then Col := DopCol;
end
else
Col := TagCol
else
Col := TextCol;
RichEdit.SelAttributes.Color := Col;
iDop := 0;
if (s = '>') or (s = '}') then isTag := False;
end;

RichEdit.SelLength := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.Lines.BeginUpdate;
HTMLSyntax(RichEdit1, clBlue, clRed, clGreen);
RichEdit1.Lines.EndUpdate;
end;

Question:
I want an speakable password program!

Answer:
Please check this:

function SpeakAblePassWord: string;
const
conso: array [0..19] of Char = ('b', 'c', 'd', 'f', 'g', 'h', 'j',
'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
vocal: array [0..4] of Char = ('a', 'e', 'i', 'o', 'u');
var
i: Integer;
begin
Result := '';
for i := 1 to 4 do
begin
Result := Result + conso[Random(19)];
Result := Result + vocal[Random(4)];
end;
end;


CLICK TO REGISTER