Edit File on Click of a button in Lazarus - lazarus

Like I posted in a previous thread I want to create a little program which edits one line in a .ini file. Now I have implemented a button but don't further. I basically want to implement the following scenario:
1) Click Button
2) Because of button click, program opens .txt/.ini file (in background) the file is located in the same folder
3) One word in text file is changed with new word
4) file gets saved
5) message pops up
procedure TLauncher.ButtonClick(Sender: TObject);
var
begin
ShowMessage('.Ini-File was edited')
end;

That's simple to do, if you split what you want to do into procedures that only
do one thing each.
Assume your form has a string variable IniFileName which you initialize however
you want, e.g. using a TOpenDialog. Then you can have
procedure TForm1.LoadIni;
begin
Memo1.Lines.LoadfromFile(IniFileName);
end;
procedure TForm1.SaveIni;
begin
Memo1.Lines.SaveToFile(IniFileName);
end;
procedure TForm1.Button1Click;
begin
if OpenDialog1.Execute then begin
IniFileName := OpenDialog1.FileName;
LoadIni;
end;
end;
procedure TForm1.Button2Click;
begin
SaveIni;
ShowMessage(IniFileName + ' saved to disk');
end;

Related

Two event on one button click Oracle Apex

First I have loop in pl/sql example (EX 1)
begin
declare
l_string varchar2(4000);
begin
:P15_URL_PARAMETER := '';
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
l_string := l_string || APEX_APPLICATION.G_F01(i) || '-';
END LOOP;
:P15_URL_PARAMETER := l_string;
end;
end;
After P15_URL_PARAMETER field get value from above plsql I need call
redirect to url example (EX 2)
javascript:var a = window.open('f?p=800:105:&APP_SESSION.:.....xyz........&P15_URL_PARAMETER.');
In this moment, first on BUTTON_1 I call process (EX 1) and then P15_URL_PARAMETER get value on second button BUTTON_2 call redirect to url (EX 2). All work fine, but is it possible (EX 1 and EX 2) call on one button click?
Tnx
I guess so. That would be done by creating a dynamic action with two true actions:
one is "Execute PL/SQL Code" (which is the first piece of code you posted)
another one is "Execute JavaScript Code" (which is the second code you posted)

Is there anyway to put a procedure in utl_file to print part of the file content in plsql?

I try to print something to a file. The file has header, body, footer and each of them has some function in it respectively. Is there a way I can separate it into each procedure then combine them as one procedure?
For instance, I made a procedure with open, write, close file process, and then I put the header procedure, body, footer procedure inside it,
Code idea demonstrates like below, but the error message said ORA-06550 and PLS-00222: no function with name 'header' exists in this scope.
This is why I want to know if SQL could do this way?
procedure print_document is
-- Variables for writing data to file
v_file utl_file.file_type;
v_utlDir VARCHAR2(35) := get_dir('Directory','Dir');
v_utlFileName VARCHAR2(35);
Begin
--Open file and Write to file
SELECT test.dat' into v_utlfilename from dual;
v_file := utl_file.fopen(v_utlDir, v_utlFileName, 'W');
--print header, body, footer
utl_file.put_line(v_file,header); -- the header is a procedure
utl_file.put_line(v_file,body);
utl_file.put_line(v_file,footer);
utl_file.fclose(v_file);
--
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error in SQL. The error is');
DBMS_OUTPUT.PUT_LINE(SQLERRM);
End;
Ideally, if I call print_document procedure then it will print all the lines to the cmd console.

Loop trough data block with different time elapsed

I'm using Oracle Forms 10g, on a Oracle Database version 7.
I have a data block who is refreshed (new execute_query) from two different ways:
1.A button how implement this:
PROCEDURE refresh
IS
ID NUMBER;
BEGIN
ID := :myblock.id;
GO_BLOCK ('myBlock');
EXECUTE_QUERY;
-- Keep the record selected after the refresh
POSITION (ID);
END;
PROCEDURE POSITION (ID IN NUMBER)
IS
L_record NUMBER (5) := NULL;
BEGIN
GO_BLOCK ('myBlock');
GO_ITEM ('myBlock.ID');
FIRST_RECORD;
LOOP
IF :myblock.id = myID THEN
L_record := GET_BLOCK_PROPERTY ('myBlock', CURRENT_RECORD);
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE' OR :myblock.ID = myID;
NEXT_RECORD;
END LOOP;
IF L_record IS NOT NULL THEN
GO_RECORD (L_record);
END IF;
END;
2.The other is one other button who do this:
PROCEDURE newRefresh
IS
ID NUMBER;
BEGIN
ID := :myblock.id;
refresh;
POSITION (ID);
END;
Ignoring the reason of this two buttons, my problem is when I call the second button, the first call of POSITION procedure takes too long (because we have a lot of records and POST_QUERY trigger), but the second call of the same procedure is very fast.
What is the reason of this behaviour? Is there a fastest way of positioning the focus on the same record selected before?
Why is it slow? Who knows ... All we can do is to blindly guess and still be VERY far from actual reason. Too few data to compute. I'd suggest you to run the form in debug mode (as Forms 10g allows it) and trace its execution to see what's going on.
As of faster positioning: consider this approach:
create a parameter, let's call it position
refresh button(s) would:
-- save current position
:parameter.position := :system.trigger_record;
go_block('myBlock');
execute_query;
-- go to previously saved position
go_record(:parameter.position);
(BTW, are you really using Oracle database version 7.x? Whoa!)

Oracle: Call stored procedure inside the package

I have the following package:
create or replace package PKG1
as
procedure INIT
(
nRN in number,
nREC_TYPE in number,
nIDENT out number
);
I'm not sure how to call it from PL/SQL Developer environment. I've tried this:
DECLARE
procId NUMBER;
BEGIN
EXECUTE PKG1.INIT(1143824, 0, procId);
DBMS_OUTPUT.PUT_LINE(procId);
END;
But, there's an ORA-06550 (PLS-00103) error.
As you can see I have 2 input and 1 output parameter. I want to print out output parameter. That's all.
You're nearly there, just take out the EXECUTE:
DECLARE
procId NUMBER;
BEGIN
PKG1.INIT(1143824, 0, procId);
DBMS_OUTPUT.PUT_LINE(procId);
END;
To those that are incline to use GUI:
Click Right mouse button on procecdure name then select Test
Then in new window you will see script generated just add the parameters and click on Start Debugger or F9
Hope this saves you some time.

How can I hide Cursor in Windows? (delphi)

I want my program to work sort of like Team Player. Multi mice, multi cursor but only one focus. But the problem is I can't hide the default cursor. I only want it to be invisible.
So far this works inside my application only.
ShowCursor(false);
and
Screen.Cursor:=crNone;
Is there a way to hide the cursor for the entire system (just until I close my application)?
EDIT:
This doesn't work:
procedure myShowCursor(Show :boolean);
var cursor1, cursor2: HCursor;
begin
cursor1 :=CopyIcon(Screen.Cursors[crDefault]);
cursor2 := LoadCursorFromFile('blank\blank.cur');
if Show then
SetSystemCursor(cursor1, OCR_NORMAL)
else
SetSystemCursor(cursor2, OCR_NORMAL);
end;
This works: (but I can't exactly use this)
procedure myShowCursor;
var cursor1, cursor2: HCursor;
begin
cursor1 :=CopyIcon(Screen.Cursors[crDefault]);
cursor2 := LoadCursorFromFile('blank\blank.cur');
SetSystemCursor(cursor2, OCR_NORMAL);
SetSystemCursor(cursor1, OCR_NORMAL)
end;
SOLVED: restored system cursors by SystemParametersInfo
procedure TForm1.myShowCursor(Show :boolean);
var cursor1: HCursor;
begin
cursor1 := LoadCursorFromFile('blank\blank.cur');
if Show then
SystemParametersInfo(SPI_SETCURSORS,0,0,WM_SETTINGCHANGE or SPIF_UPDATEINIFILE )
else
SetSystemCursor(cursor1, OCR_NORMAL);
end;
first download a blank cursor, you can get it from many places,i downloaded it from
http://pc.autons.net/stuff/blanks/blank.zip
,extact blank.zip then copy and paste blank.cur to a desired location(i am saving it to 'c:\blank.cur' for this example)
then try this code:
var cursor1, cursor2: HCursor;
begin
cursor1 := CopyIcon(Screen.Cursors[crDefault]);
cursor2 := LoadCursorFromFile('c:\blank.cur');
SetSystemCursor(cursor2, OCR_NORMAL);//to hide cursor
Sleep(2000);
SetSystemCursor(cursor1, OCR_NORMAL);//to show cursor again
end;
hope this helps

Resources