AsyncKeyDown pressed key value - intraweb

Using Intraweb in Delphi,
Is there a way to find AsyncKeyDown pressed key value?
I know its somehow inside EventParams: TStringList but I only can see it through the Local variable list at runtime like this, string = 'char=i', and I cannot really get it out from there as a char unless I make a special function to pull it from there, so I'm thinking if there is a simple way to just get the pressed key as char from AsyncKeyDown ?

I know it's been a long time since the question was asked. But it will be good for those who still need it. I used it and working. You can get it as char as following:
http://www.devsuperpage.com/search/Articles.aspx?G=2&ArtID=52557
procedure TfrmLHasta.edSuzAsyncKeyDown(Sender: TObject;
EventParams: TStringList);
var
lKey: char;
begin
lKey := Chr(StrToInt(EventParams.Values['which']));
// WebApplication.ShowMessage(lKey);
if lKey = #13 then DoSomething;
end;

Related

arduino: loop until int gets value assigned to it

I am trying to get a value from serial input. The rest of the programm behaves different if the value changes. This value gest assigned once in the ```void setup()``` function.
My goal is to let the program run an infinite loop or something similar until a value (type int) is recived, and only then resume the flow.
I know about ```Serial.parseInt()``` and tried to implement it ``` while (variable == null) variable = Serial.parseInt() ``` but I got an error that 'null' was not declared in this scope.
Any suggestions?
Oke, i was kinda dumb.
There is an easy way, simply check
while (!variable)
variable = Serial.parseInt()
This worked for me and should work for you as well

How to use variable while creating HotString in my script (AutoHotKey)

I'm trying to create a hotstring which needs to take a variable value as it's key
Example:
b := "btw"
::%b%::
Send, By the way
return
When i type btw and space, it must replace the text with "By the way"
Per the documentation: "[v1.1.28+]: Hotstrings can be created dynamically by means of the Hotstring function, which can also modify, disable, or enable the script's existing hotstrings individually."
Untested example:
b := "::btw"
Hotstring(b,"by the way")

Cast to TObject

I am struggling to get the ItemIndex of my a Item in my TComoBox...
Usually that doesn't seem to be a hard thing to do for me... but somehow when i try to cast my String(which I got from a SQL select) to a TObject. That doesn't seem to work. I tried to debug my code with writing the String manually into the Object like so:
TObject('U');
That somehow does work, i just cant explain that...
The way i fill the ComoBox:
for i := Low(_VerkaufTypenBez) to High(_VerkaufTypenBez) do
begin
CBBelegart.AddItem(VerkaufTypenBez(i), Tobject(VerkaufTypenShort[i]));
end;
The way i tried to set the Index:
CB.ItemIndex := CB.Items.IndexOfObject(TObject(SetIndexWithSQL('select top 1 * from KOMSAconfig_Allgemein', 'Belegart'))); //index = -1
helper := 'U';
CB.ItemIndex := CB.Items.IndexOfObject(TObject(helper)); //index = -1
CB.ItemIndex := CB.Items.IndexOfObject(TObject('U')); //index = 1
Any suggestions?
This is what happens when you try to use a visual control as if it were a general purpose container. A visual control is used purely for display and user interaction. Don't try to bend it to do more than that.
In your scenario it is pointless to attempt to add a second string into the combo box. Stop doing that. Change your loop that populates to be like so:
for i := Low(_VerkaufTypenBez) to High(_VerkaufTypenBez) do
begin
CBBelegart.Items.Add(VerkaufTypenBez(i));
end;
The other string is held in an array like structure and seemingly can be accessed like this: VerkaufTypenShort[i]. So, if you want to lookup the index of a particular value, that can be done like so:
function GetIndexFromShortString(const Value: string): Integer;
begin
for Result := Low(_VerkaufTypenBez) to High(_VerkaufTypenBez) do
if VerkaufTypenShort[Result]=Value then
exit;
Result := -1;
end;
Notice that this function is completely independent of the visual control. You should strive to use visual controls for the bare minimum, and write your business logic without reference to any visual controls.
Your problem here seems to be that you get two strings from your query, where one is used as display text and the other is needed for internal lookups (coming from a different query).
I see two ways to solve this:
change your second query, so it returns the string, that is used in the combobox
have a lookup in your form that connects both strings
For the second you could use a TDictionary. My approach here assumes that filling the combobox is done only in one loop and there aren't strings added or removed dynamically.
Add the Dictionary to your form:
TForm1 = class(TForm)
...
private
FLookUp: TDictionary<string, Integer>;
In the FormCreate and FormDestroy events create and destroy your Dictionary.
FLookUp := TDictionary<string, Integer>.Create;
FLookUp.Free;
In the loop you use to fill the Combobox, store the Indices and connect them to your lookup-strings (I just copied your loop, assuming that it works as is).
procedure TForm1.FillCombo;
var
Index, I: Integer;
begin
FLookUp.Clear;
for i := Low(_VerkaufTypenBez) to High(_VerkaufTypenBez) do
begin
Index := CBBelegart.Items.Add(VerkaufTypenBez(i));
FLookUp.Add(VerkaufTypenShort[i], Index);
end;
end;
Now you can look for the correct Index using that Dictionary
function TForm1.GetIndexOfString(const Value: string): Integer;
begin
if not FLookUp.TryGetValue(Value, Result) then
Result := -1;
end;
Use it like
CB.ItemIndex := GetIndexOfString(SetIndexWithSQL(...));

Golang server: send JSON with SQL query result that has variable number of columns

I'm creating a little implementation of RESTful API with Go server.
I'm extracting query parameters from URL (I know it's not safe, I'll try to fix this later on, but if you have any recommendations even on this topic, they would be helpful).
I have table name, desired columns and some conditions saved in 3 sring variables.
I'm using this query:
rows, _ := db.Query(fmt.Sprintf("SELECT %s FROM %s WHERE %s", columns, table, conditions))
I want to send the query result back to my frontend, as JSON. I have variable number of unknown columns, so I can't do it "standard" way.
One solution I can think of is to build a JSON string "manually" from from query result and rows.Columns().
But I'd like to do this in a more sofisticated way using something like variadic interface and stuff like that. The problem is, even after trying a lot, I still dont understand how it works.
I tried using following code
cols, err := rows.Columns() // Get the column names; remember to check err
vals := make([]sql.RawBytes, len(cols)) // Allocate enough values
ints := make([]interface{}, len(cols)) // Make a slice of []interface{}
for i := range ints {
vals[i] = &ints[i] // Copy references into the slice
}
for rows.Next() {
err := rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
// and you can use type introspection and type assertions
// to fetch the column into a typed variable.
}
from this tutorial but it doesn't work, I'm getting errors like
cannot use &ints[i] (type *interface {}) as type sql.RawBytes in assignment
And even if it'd work, I dont understand it.
Does anyone have a good solution for this? Some explanation would be great aswell.
Thanks a lot.
The first problem is here:
for i := range ints {
vals[i] = &ints[i] // Copy references into the slice
}
This is you setting values that are meant to be RawBytes as pointers to interfaces.
Before I explain what that's meant to be doing I'll see if I can explain what the general idea is here.
So normally when getting the response from SQL in Go you'd have a slice with each column and type (id int, name string, ...) so you can then read each SQL record into this slice and each column will be mapped to the value of the same type.
For cases like yours where you will have more variety in the response from SQL and need Go to handle it, you'd do this:
for i := range ints {
ints[i] = &vals[i] // Copy references into the slice
}
What this is saying is each of your interface values holds a pointer to the vals array that will hold the response from SQL. (In my examples I use [][]byte instead of RawBytes so value in vals would be a slice of byte values from SQL.)
You'd then do:
err := rows.Scan(ints...)
Since interface can evaluate to any type, when the ints array becomes populated it will accept any value then update the position in vals array based on the pointer with the value from SQL as a RawBytes type.
HTH

Passing Parameter from SQL-File to procedure

Sadly I don't know the exact names for each part, probably I can explain it:
We have a SQL-File, which is defined like this:
declare
l_exec boolean := true;
l_print boolean := false;
---
begin
dbms_output.enable;
for t in (
And so on. We use this to create some Triggers etc. in our Oracle-Database.
Now this File grew to much and I need to split it up.
So I created a Main-File, which is looking like this:
SET SERVEROUTPUT on
set feedback off
DEFINE l_exec = TRUE;
DEFINE l_print = FALSE;
ACCEPT ora_instance PROMPT "Zielinstanz angeben [123|...]: " DEFAULT somedefault
CONNECT somelogins
PROMPT -- GENERATING CODE --
#file1 l_print, l_exec
This would work fine, but I'd like to pass the l_exec and l_print to each file. I read in some other Threads passing the parameters like this is ok. But the problem is: I not only need to pass it from file to file, but I need to pass it to the Procedure-Block after begin.
I'm not sure if I made it understandable, but I'd like to use the variable I pass at #file1 in the begin block of the Files.
Is this kindahow possible? I googled alot about SQLPlus, but didn't find a solution so far.
Thanks as always and a nice week
Matthias
Ok, so if your main file has the call to your sub-file:
...
CONNECT somelogins
PROMPT -- GENERATING CODE --
#file1 l_print, l_exec
then your sub-file can use the parameters in a positional manner thus:
declare
l_print boolean := &1;
l_exec boolean := &2;
---
begin
dbms_output.enable;
for t in (