select more than one checkbox to execute condition - windows

I want a text file to show contents in memo1 once I have selected 2 checkboxes.
How would I do this?
I tried the code below but I can't seem to get it right.
if CheckBox1.Checked and CheckBox2.Checked then
begin
memo1.lines.LoadFromFile('files\RS.txt');
end;
I also want to be able to select the checkboxes individually Like:
(pointing this out in case combining them prevents checking them individually)
Checkbox1:
procedure TForm1.CheckBox1Change(Sender: TObject);
begin
memo1.lines.LoadFromFile('files\R.txt');
end;
Checkbox2:
procedure TForm1.CheckBox2Change(Sender: TObject);
begin
memo1.lines.LoadFromFile('files\S.txt');
end;
Any suggestions/Improvements will be appreciated.
Running Lazarus IDE v1.6.4
Windows 10 x64

I'm assuming your objective is to generate a filename which depends on the
particular combination of the boolean states of the two checkboxes -
see example code below. The point of doing this is that it helps separate
the definition of what you want the file name to be from what you want to do
with it.
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.LoadFromFile(GetFileName);
end;
function TForm1.GetFileName: String;
begin
// Return empty string if neither checkbox is checked
Result := '';
if Checkbox1.Checked and Checkbox2.Checked then
Result := 'files\RS.txt'
else // if we reach here only one of the checkboxes, or neither, is checked
if Checkbox1.Checked then
Result := 'files\R.txt'
else
if Checkbox2.Checked then
Result := 'files\S.txt'
end;
I've assigned an empty string to the Result of the function at the outset to ensure that the Result is always defined.
Important You'll notice that the above does not use the Change events of the Checkboxes. The reason is that you may not get the result you need (or are expecting) if the Change events are never triggered - for example if one CheckBox is set to Checked in the IDE but the other isn't, and you want to get the right file name regardless of whether the user has actually clicked either one of them.

As far as I understood you want the following behaviour:
There are two check boxes
There is one memo field
Depending on the state of the two check boxes the text in the memo field shall change
If this understanding is correct:
I typically don't use Pascal but your problem seems to be independent of the programming language used. I would do it like this:
The two procedures TForm1.CheckBox1Change and TForm1.CheckBox2Change are called whenever the corresponding check box'es state changes.
I would write a third procedure and call this third procedure from both procedures. I would do nothing else than calling this third procedure in the other two procedures.
In the third procedure I would evaluate what to do - depending on the state of both check boxes.

A separate checkboxchange proocedure per event is automatically generated by the designer if you double click the event. However that is not a rigid decision.
If you have the initial codefragment in e.g. checkbox1change, you can simply point the onchange of checkbox2 to that existing checkbox1change by using the dropdown of the onchange of checkbox2

Related

How do I save a picture from a open picture dialogue to a file

Hi I'm currently using Delphi 2010.
I basically have a form where a user has to enter information about themselves and upload a picture. I have an Image component on my form. I did some research and many of the websites I looked at said to use a OpenPictureDialogue to allow the user to select an image and display it in the Image component.
My question is, how can I save this image to a file on my computer? Keeping in mind I will have multiple users adding their picture and that I will have to use the picture later on again, basically I want to use the LoadFromFile procedure to display the picture in my program later on.
I also read many websites saying to use the SavePictureDialogue, but that allows the user to select the file they want the image to be saved to and I don't want that, I want it to save to a file that only I can access.
I have this so far, I know it is very limited.
if opdAcc.Execute then
begin
if opdAcc.FileName <> '' then
begin
imgAccImage.Picture.LoadFromFile(opdAcc.FileName);
end;
end;
I am a student and my knowledge is quite limited and I would appreciate any help. :)
First of all, there is no place on the hard drive that only you can access. But you can create a folder to store your files and copy users' pictures there. This reduces the likelihood that the user will have access to these files. The usual folder for storing such files is the AppData folder. It is better to create a folder with the same name as your application in AppData and store such files there.
Suppose the GetPicturesDirectoryPath function generates the address of such a folder and ensures that this folder has already been created or will be created. The next step is to generate a unique name for the file you want to store. Note that multiple users may select files with the same name. In this case, after copying the picture selected by the second user, the image file will be written over the previous user's file. If a unique identifier is assigned to each user, this identifier is the best choice for the picture file name. But you can use the GetGUIDFileName function to create a unique address. Make sure the generated address is kept with the rest of the user information, or the connection between the copied file and the user will be lost. The implementation of all these will be something like the following:
uses IOUtils;
function GetAppDataDirectoryPath: string;
begin
...
end;
function GetPicturesDirectoryPath: string;
begin
Result := TPath.Combine(GetAppDataDirectoryPath, 'MyApp');
TDirectory.CreateDirectory(Result);
end;
function GetUniqueFilePath(const Extension: string): string;
begin
Result := TPath.ChangeExtension(
TPath.Combine(GetPicturesDirectoryPath, TPath.GetGUIDFileName),
Extension);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
DestPath: string;
begin
OpenPictureDialog1.Options := OpenPictureDialog1.Options +
[ofFileMustExist]; // make sure that selected file exists
if OpenPictureDialog1.Execute then
begin
DestPath := GetUniqueFilePath(TPath.GetExtension(OpenPictureDialog1.FileName));
TFile.Copy(OpenPictureDialog1.FileName, DestPath);
if TFile.Exists(DestPath) then
Image1.Picture.LoadFromFile(DestPath)
else
ShowMessage('Well, something went wrong!');
end;
end;
Read this to implement GetAppDataDirectoryPath.

Change PDF out put file name dynamically in oracle reports

Please guide how to change output PDF file name at run time
I am using below code in after parameter form trigger but its not working :
:DESNAME := 'INVOICE_'||:P_CLIENT||'.PDF';
Please guide me..
You didn't mention which Reports version you use; up to 6i program that is used to create reports was called "Reports Builder", while later versions use name "Reports Developer". Doesn't really matter, but - if you open Reports Online Help System (navigate to "Help" menu) and search for DESNAME, you'll find which executables can be used to set DESNAME's value. RWBUILDER is not among them. And yes, rwbuilder is Builder's and/or Developer's EXE name.
It means that you're out of luck, at least regarding the way you're trying to set DESNAME's value. You can't set it in any of Reports' triggers. I mean, you can, but it won't take any effect.
However, if you call the report from, for example, a form developed by Oracle Forms, then you'd use RWRUN which can specify DESNAME value and yes, you can dynamically create it.
For some more info, do read Help I pointed you to previously.
Among several ways of calling Reports from Forms, i can suggest you to use adding RP2RRO.pll to your Form :
And then, add parameters related to this pll :
And you may call your reports by this code :
Pr_Print_Rp2Rro('Rep_Invoice','|Prm1|Prm2|','|'||:Prm1||'|'||:Prm2||'|','no','INVOICE_'||:P_Client||'.PDF');
assuming you have two user defined parameters namely : Prm1 & Prm2. And Pr_Print_Rp2Rro is a procedure with the following code :
Procedure Pr_Print_Rp2Rro(
i_rep_name varchar2,
i_prm_name varchar2,
i_prm_val varchar2,
i_param_frm varchar2, -- 'Yes','No'
i_desname varchar2,
i_destype varchar2 default 'FILE'
) Is
plist ParamList;
arr_prm_name owa.vc_arr;
arr_prm_val owa.vc_arr;
Begin
plist := Get_Parameter_List('REPPARAM');
if not Id_Null(plist) then
Destroy_Parameter_List('REPPARAM');
end if;
plist := Create_Parameter_List('REPPARAM');
Add_Parameter(plist, 'PARAMFORM', Text_Parameter, i_param_frm);
Rp2rro.SetDestype(i_destype);
Rp2rro.SetDesname(i_desname);
for i in 1..100
loop
arr_prm_name(i) := substr(i_prm_name,instr(i_prm_name,'|',1,i)+1,instr(i_prm_name,'|',1,1+i)-instr(i_prm_name,'|',1,i)-1);
arr_prm_val(i) := substr(i_prm_val,instr(i_prm_val,'|',1,i)+1,instr(i_prm_val,'|',1,1+i)-instr(i_prm_val,'|',1,i)-1);
if length(arr_prm_name(i)) > 0 then
Add_Parameter( plist, arr_prm_name(i) , Text_Parameter, arr_prm_val(i) );
end if;
end loop;
Rp2rro.Rp2rro_Run_Product(Reports, i_rep_name, Synchronous, Runtime,Filesystem, plist,null);
End ;
As you may have noticed this procedure contains a method Rp2rro.SetDesname(i_desname) which you could use and manage your task to create Report names spesific to your customer, unless you set your Destype parameter as CACHE.

Testing a function in PL/SQL Developer

This is my function:
FUNCTION GET(V_IN IN NUMBER) RETURN VARCHAR2 AS
V_OUT VARCHAR2(1000);
BEGIN
function body
END;
When I right click the function and click on test, I am getting the following:
begin
-- Call the function
:result := pkg.get(V_IN => :V_IN);
end;
How do I substitute a value for this variable V_IN? I need to test it for a number, say 940.
When I try the code:
declare
r varchar2(2000);
begin
-- Call the function
r := pkg.get(940);
end;
I am getting an error:
ORA-01036: illegal variable name/number
Can you suggest various ways of calling this function?
PS:
Tool used: PL/SQL Developer Allround Automations. Version 8.0.1.1502
Oracle Database 11g Enterprise Edition
Once you've clicked on your function and clicked on Test in the context menu a Test window is brought up with the code you've shown. There are two panes in this window - the top pane shows the code which PL/SQL Developer generated to invoke the function, and the lower pane contains a list of the parameters to your function. In the lower pane of the Test window there's a list of the parameters to the function with three columns - Variable, Type, and Value. Type the value you want into the Value column in the row with your parameter's name, then click on the Start Debugger button (top left of the Test window, under the 'Test Script' tab's name), then click on the Run button (immediately to the right of the Start Debugger button).
Best of luck.
"How do I substitute a value for this variable V_IN? I "
When you run the test in PLSQL Developer the bottom pane of the test window is a property list for all the substitution variables. You define the datatype and the input values (when appropriate). Output values are available in this window after the test is run.
"ORA-01036: illegal variable name/number"
Not sure what causes this. It's probably not PLSQL Developer but a bug in your function code (which you have not posted).
I was able to run the function as follows:
declare
v varchar2(1000);
begin
select pkg.get(940) into v from dual;
dbms_output.put_line(v);
end;
Also, as per APC's comment, there is a property list(the small window appearing below the PL/SQL worksheet, having Variable, Type and Value fields). You need to enter the value which you wish to pass in the value field and click on Execute (shortcut-F8). The output will be shown and highlighted in yellow in the same property list window. Click below link to refer the screenshot:
Function Call with single parameter
I assume you are still in pl/sql "Test window", when you modified the original test code to your custom. Pl/sql sometimes is buggy. Open a new "SQL window" and try to run there with dbms_output.put_line() to see the result.

Output window doesn't show Pascal (Lazarus compiler)

I was trying to make a little test program to count how many times letter 'a' appears in an text without using string type:
program PascalTest;
uses WinCrt;
var
a:integer;
ch:char;
begin
a:=0;
writeln('Input text: ');
read(ch);
while ch <>'.' do // '.' marking the end of text ("eoln" could've been used instead)//
begin
case ch of
'A','a':a:=a+1;
end;
read(ch);
end;
writeln(a);
readln;
readln; //forcing output window to stay open//
end.
I noticed that if I dont add another 'readln' statement at the end , the output window will not show results (it will flash in an instant if u will).This is happening only with this program.All the other ones require only one 'readln' so the window can stay open. Can somebody explain to me why is another 'readln' statement needed in this case?
The first readln ends the while loop. Note that you can enter many '.' without loop exit. Further note the writeln(a) is delayed until you press <Enter>. The second readln allows you to view the output.
Make a test: Uncomment both readln and see if you can end the program by entering a '.'.
WinCrt is a consoleless CRT to use in combination with unit GRAPH.
Use unit Crt for normal console output.

VHDL integer'image Returns "0"

Here is my dilemma:
I'm very new to programming in VHDL, and I'm currently working on an independent study project for a university class. I've made some descent headway, but I've run into an issue I haven't been able to solve.
What I'm trying to do is to display a "register" (or registers) on an LCD monitor and have it update periodically. For the time being, these values will always be integer numbers.
I have code written which displays numbers properly on the screen if that value is passed as a variable that is never altered or as a hard-coded value. However, I want to update a variable by adding to it, then pass that to my function and display it.
Essentially what I'm trying to do is this:
Every 'x' clock ticks, increment a register's value, pass that to my update_screen function which returns a new screen, and then display that further below. However, once I increment or change through reassignment (doesn't seem to matter if it is variable or a signal), all I see is '0' on the screen.
So... The following code properly updates my display unless I uncomment the commented lines. At that point, it just shows '0'.
--currentRegVal := currentRegVal + 1;
--screenVal <= 25;
-- screen holds the values for the current screen
-- The second argument is the row on the screen to be updated
-- The third argument is the value to display there
screen := update_screen(screen, 1, currentRegVal);
screen := update_screen(screen, 0, screenVal + 25);
The problem seems to be stemming from the integer'image attribute (or more accurately, my understanding of it). When I pass in a hardcoded value or a variable that hasn't been altered, it returns what I expect. However, as soon as I modified the variable/signal in ANY way it seems to return the string "0".
Below is my update_screen function:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
-- A function may declare local variables. These do not retain their values between successive calls,
-- but are re-initialised each time. Array-type parameters may be unconstrained:
constant screenWidth: integer := screen'length(2);
constant strRegVal: string := integer'image(regVal);
constant strRegLen: integer := strRegVal'length;
variable newScreen: screenData := screen;
begin
for dex in 1 to screenWidth loop
if dex <= strRegLen then
newScreen(reg, dex-1) := strRegVal(dex);
else
newScreen(reg, dex-1) := ' ';
end if;
-- The next two ifs were my attempt to figure out what
-- was going on...
--The value itself never seems to be 0... the screen is not all 5's
if regVal = 0 then
newScreen := (others => (others => '5'));
end if;
-- But the string value is "0" if the variable/signal is ever modified...
-- 'd' shows up in the designated row.
if strRegVal = "0" then
newScreen(reg*3, 1) := 'd';
end if;
end loop;
return newScreen;
end update_screen;
A couple important points (added 2011-07-26):
I'm using the Quartus II free (web) edition to design/compile my project.
The code which is updating the variables is in a process.
At the time of the original posting, the only steps I had taken were to compile my code and program an Altera DE2 FPGA board with the result (I wasn't sure how to perform any kind of simulations).
Thanks in advance for any help and advice. Also, as I said, I'm new to VHDL programming, so if there is a much better way to do something I'm doing here, please let me know. I would also greatly appreciate useful links to any resources about the language itself.
Update (2011-07-26):
I downloaded GHDL as Martin Thompson suggested, but I have not actually used it yet because I'm not sure how to go about doing so with my current Quartus II project (or if I even can). I'll have to do some reading before it is useful to me. However, yesterday I managed to install ModelSim-Altera which works directly with Quartus II and allowed me to perform some simulation.
I did my best to set up some waveforms that would allow me to test, and I was at least able to examine the execution of the code which I believed to be failing. However, during simulation, I've verified in multiple ways that the "screen" object does contain the value I want it to contain after the *screen_update* function runs. When running on the Altera DE2, however, it still fails.
Note: I did verify that the screen actually does update by directly setting the value of a particular element on the screen to different values depending on whether or not the currentRegVal is even or odd.
I'll plan on posting some code tomorrow, but for now:
What reasons are there that simulation would provide different results? My guess is something to due with timing, but it is really just a guess. If I am correct, how can I go about trying to resolve the issue?
I guess the problem is related to the fact that you declared strRegVal as a constant. I think it should better be a variable, e.g. something like this might work:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
...
variable strRegVal: string;
variable strRegLen: integer;
...
begin
strRegVal := integer'image(regVal);
strRegLen := strRegVal'length;
...
end update_screen;
Assuming this code is in a process:
screenVal <= 25;
-... snip...
screen := update_screen(screen, 0, screenVal + 25);
screenVal won't have updated to a new value yet (unless some time passes - a wait statement between the write and the read)

Resources