Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 26 days ago.
Improve this question
According to the Parameter hints in Delphi 11.1 the MessageDlg should support custom button names defined in an array of strings in the last parameter.
e.g.
I cannot get this to work. I declared a constant 3 element array of string but the compiler claims there is no overloaded version of MessageDlg with this format.
Can anyone show me how this should work or is it an error in the parameter help.
no problem it works fine
var
CustomButtonCaptions: array of string;
begin
SetLength(CustomButtonCaptions , 5 );
CustomButtonCaptions[0] := 'Button-1';
CustomButtonCaptions[1] := 'Button-2';
CustomButtonCaptions[2] := 'Button-3';
CustomButtonCaptions[3] := 'Button-4';
CustomButtonCaptions[4] := 'Button-5';
case MessageDlg('MSG',TMsgDlgType.mtConfirmation,mbYesAllNoAllCancel,0,TMsgDlgBtn.mbClose,CustomButtonCaptions) of
0:
begin
end;
end;
end;
// Or
MessageDlg('MSG',TMsgDlgType.mtConfirmation,mbYesAllNoAllCancel,0,TMsgDlgBtn.mbClose, ['Button-1','Button-2','Button-3','Button-4','Button-5']);
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I use Delphi 2009. I receive a text as String that looks like 'Визгунов (ранний) {VHS}'. Using online decoders, I was able to determine that it's actually Win-1251 codepage.
What should I do to restore it back to normal, in other words to make it readable again?
var s: string;
rbs: RawByteString;
begin
rbs := Utf8ToAnsi('Визгунов (ранний) {VHS}');
SetCodePage(rbs, 1251, false);
s := string(rbs); // s = 'Визгунов (ранний) {VHS}'
end;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have created a custom form, to resamble a dialog. Then I overloaded the MessageDlg function in a special unit to call this form. Great, its working A-OK.
When I call the form, it's shown as a Modal, and inside this modal I need the caller form name.
Example: FormA calls unit U_Functions that overloads MessageDlg. Then U_Functions calls FormDLG and it's shown. Inside FormDLG I execute function "GetParentFormName" and it returns "FormA".
I already tried GetForegroundWindow, but it returns the same thing as Self. Self.Parent is null. How can I get the modal caller's reference(TForm)?
Example of flow
FormA:
procedure TFormA.Button1Click(Sender: TObject);
begin
MessageDlg('Call Dialog', mtWarning, [mbOK], 0);
end;
U_Functions
function MessageDlg(Msg: String; Icone: TMsgDlgType; Botoes: TMsgDlgButtons): Integer; overload;
begin
Result := FormDialog.fn_ShowMessage(msg, Icone, Botoes);
end;
FormDialog
function FormDialog.fn_ShowMessage(Msg: String; Icone: TMsgDlgType; Botoes: TMsgDlgButtons): Integer;
begin
// Get FormA's name
end;
Remy Lebeau's approach (Screen.ActiveForm) accomplished exactly what I was looking for. Thank you so much for your time.
Since there's a middle unit, it gathered the callers name, and sent via parameter to the third form (Dialog).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a form class TfrmWelcome and I want to be able to dynamically add
a memo to it when a button is clicked in the main part of the form (frmWelcome.MainPanelSourceEditor).
My unsuccessful attempt at some code is below. I get the error
"undeclared identifier WelcomeMemo". How could I get this to compile and work?
type
WelcomeMemo : TMemo;
end;
implementation
procedure SetHelpWelcome;
begin
WelcomeMemo : TMemo.Create(frmWelcome);
with TMemo(FindComponent('WelcomeMemo')) do
begin
Parent := frmWelcome.MainPanelSourceEditor;
If what you are trying to do is to add a memo to your frmWelcome at runtime, a better (but still not very good) way to do it would be like this:
procedure SetHelpWelcome;
var
WelcomeMemo : TMemo;
begin
WelcomeMemo := TMemo.Create(frmWelcome);
WelcomeMemo.Parent := frmWelcome.MainPanelSourceEditor;
// set any other properties of WelcomeMemo here.
end;
This avoids the with (which you should never use especially if you are a beginner) and the completely avoidable FindComponent to find something you don't need to find in the first place if you capture it by the assignment to the WelcomeMemo local variable.
But that's still a fairly naff way of doing what you want. It would be better to have the WelcomeMemo as a member of your form, and define a method of the form to create and initialise it; you could then call the method from the OnClick handler of the button you want to use to create it. Something like (untested)
TfrmWelcome = Class(TForm)
private
fWelcomeMemo : TMemo;
procedure SetUpWelcomeMemo;
[...]
end;
procedure TfrmWelcome.SetUpWelcomeMemo;
begin
if fWelcomeMemo <> Nil then exit; // to avoid creating it more than once
fWelcomeMemo := TMemo.Create(Self);
fWelcomeMemo.Parent := Self.MainPanelSourceEditor;
// set any other properties of WelcomeMemo here.
end;
Apart from anything else, this avoids the memo's owner being set to the specific TfrmWelcome instance frmWelcome, which is an accident waiting to happen because it may not be the instance you are actually wanting to work with.
But like #J.. said, you really need to look at a beginner's tutorial if you are blundering around using trial and error the way it sounds like you are.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am working with a text file on Delphi 7 and I need to fix errors in each line of the text file, but I am not sure what code to use.
I already have the code to open and display the text file in a rich edit but I don´t know where to go from there.
AssignFile(myFile, 'Test.txt');
Reset(myFile);
while not Eof(myFile) do
begin
ReadLn(myFile, text);
Richedit.lines.add(myFile);
end;
CloseFile(myFile);
end;
You really should not use the 1970's assignfile/reset etc calls anymore.
The following code will work:
RichEdit1.Lines.LoadFromFile(Filename);
When saving the file you do:
RichEdit1.Lines.SaveToFile(Filename);
If you want to examine the lines of text before injecting (so to spreak) them into the edit control do this:
var
SL: TStringList;
i: integer;
begin
SL:= TStringList.Create;
try
SL.LoadFromFile(Filename);
for i:= 0 to SL.Count -1 do begin
//Fixup is a function that reads the line and returns a corrected line.
SL[i]:= FixUp(SL[i]);
end;
RichEdit1.Lines.Assign(SL);
finally
SL.Free;
end;
end;
If you want to make sure the file is a pure text file, use a TMemo instead.
It works the same as above with TRichEdit.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Im using a IF code in a IF code :
if Label1.Caption=Label2.Caption then
begin
Form1.Close;
Form2.Show;
end
if Label2.Caption=Label3.Caption then
begin
Form1.Close;
Form2.Show;
end
end;
I keep getting a error of missing operator of semicolon
Could someone please how to make a simple IF in an IF with more lines(begin/end) ?
You need to separate statements with a semi-colon.
begin
if ... then
begin
....
end; // <--- add missing semi colon
if ... then
begin
....
end; // <-- semi-colon not needed, but looks silly if omitted
end;
The two if statements in your code need to be separated. Pascal syntax requires statements to be separated by semi-colons. The official language guide has comprehensive coverage of this area of the language's syntax: http://docwiki.embarcadero.com/RADStudio/en/Declarations_and_Statements
One final point. You indicate twice in the question that the second if is nested inside the first. That is not so. They are separate statements, one after the other. So if both conditions evaluate to True you will call Form1.Close twice, and Form2.Show twice. It seems likely that's not your intention, but I'm not in a position to guess what your true intent is.
I think you mean to want this:
if Label1.Caption = Label2.Caption then
if Label2.Caption = Label3.Caption then
begin
Form1.Close;
Form2.Show;
end;
Which can be shortened into:
if (Label1.Caption = Label2.Caption) and (Label2.Caption = Label3.Caption) then
begin
Form1.Close;
Form2.Show;
end;