call by value and call by reference in Delphi
- User
call by value and call by reference in Delphi
- Assistant
In Delphi, parameters can be passed to functions and procedures either by value or by reference.
Call by Value: In call by value method, the actual value passed to the parameter is copied into a temporary variable within the function or procedure. The changes made to the parameter inside the function or procedure do not affect the original value of the parameter outside the function or procedure.
Example:
procedure Square(x: Integer); begin x := x * x; writeln('Square of the number is ', x); end; var num: Integer; begin num := 5; Square(num); writeln('Value of num is still ', num); end.Output:
Square of the number is 25 Value of num is still 5Call by Reference: In call by reference method, the address of the actual parameter is passed to the function or procedure. The changes made to the parameter inside the function or procedure affect the original value of the parameter outside the function or procedure.
- User
CREATE A CURSOR IN SQL
- Assistant
In SQL, a cursor is a mechanism that allows fetching a set of rows one by one. Here is an example of how to create a cursor:
DECLARE cursor_name CURSOR FOR SELECT column_name(s) FROM table_name WHERE condition; OPEN cursor_name; FETCH NEXT FROM cursor_name INTO variable_name; WHILE @@FETCH_STATUS = 0 BEGIN -- do something with the value of variable_name FETCH NEXT FROM cursor_name INTO variable_name; END; CLOSE cursor_name; DEALLOCATE cursor_name;In this example, we first declare a cursor using the
DECLAREstatement. The cursor is given a name and the SQL statement that the cursor will fetch is specified in theSELECTstatement. TheWHEREclause is used to set any conditions on which rows to fetch. The result set of the query becomes the set of rows that the cursor will iterate over.