How to create an app with no GUI but still canuse components [closed] - delphi-xe2

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How is it possible to write an application with no gui, but I still want to use the the components?
My task is to go through a SQL database and then do stuff and the write to the eventlog.
Br
Valnurat

You should use a TDataModule. You can put non-visual components on it at design-time, assign their properties and event handlers as needed, etc.
You can create a VCL Forms project, remove the default MainForm, and then instantiate the DM in your code or set the DM to be auto-created, either will work.

#Remy's answer is probably the easiest, but as an alternative you can also just change the APPTYPE directive in a console application from CONSOLE to GUI, and create your components at runtime in code.
(Note that despite what it says, the GUI in that directive does NOT mean "display a graphic user interface"; it means "don't output to the console".)
Here's an example that just copies a test file into another file with the .bak extension, with no user interface at all. If you run it from the IDE, it will simply pause for an instant and then return; checking the destination folder will show you that both files exist, meaning it worked. Make sure, of course, that you change the filename to something that actually exists on your system first. :-)
NOTE: All exception handling intentionally left out for clarity. Of course, there should be try..except blocks in actual code; there's no need for try..finally resource protection here because the app is exiting immediately. It's a demo app, not production level code.
program Project1;
{$APPTYPE GUI}
uses
System.SysUtils, Classes;
var
InStream, OutStream: TFileStream;
const
InFile = 'E:\TempFiles\TestFile.txt';
var
OutFile: string;
begin
OutFile := ChangeFileExt(InFile, '.bak');
InStream := TFileStream.Create(InFile, fmOpenRead);
OutStream := TFileStream.Create(OutFile, fmCreate);
OutStream.CopyFrom(InStream, InStream.Size);
OutStream.Free;
InStream.Free;
end.

Related

How to create global variables once when app is launched in Go? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
Good day for all readers!
I have api service which needs key for some decrypt issues. Key calculates all time when I make request. That is wrong from an architectural point of view.
The option with environments (.env, viper...) drops because, in the future, I want to bring out this module to a separate library.
Hint me, how it is possible without using environments to calculate the key when starting the application and use it until stopping the application?
A global var starts with a capital, so it is reachable from within other packages.
But... it's actually bad behaviour, because those other packages can change it.
Having a non capital one, still means that functions in the same package can change it.
Perhaps you can use a constant?
or make a singleton variable, see :
https://goplay.tools/snippet/9k7FLYbbvoo
If you are sure you need a global variable, you can do this:
package main
var globalVar string = "My string"
func init(){
globalVar = "The new value of the variable"
}
func main(){
println(globalVar)
}

application properties vs static variables [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
While working on a Spring Boot project I got this doubt that what is better to use to Save Constant Values, application properties file or a Java Interface?
To get value from application.properties we have to declare variables in every file where for Java Interface, we will have only one declared variable referred everywhere.
Any other advantage one over other. Can anyone figure out in terms of memory efficiency?
The advantage of using application properties is you can change the value without changing code. If you think something is likely to change, or if it is different for different environments, then it would make sense to put it in the properties. You can define multiple profiles and have a properties file for each profile if needed.
If you are sure something isn’t going to change then define a constant. In that case you’re assigning a name to a value to improve the readability of the code.
This kind of thing seems unlikely to be significant enough for it to matter for performance. Performance improvement is about identifying and addressing the biggest bottleneck. This is going to be a long way down the list.
Using application properties file to save constant is preferred.
You can check this link for detailed explanation:
What is the best way to implement constants in Java?

run vbscript mhta [closed]

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 8 years ago.
Improve this question
i want to run vbscript from mhta
mshta "vbscript:window.close(msgbox("test"))"
WScript or CScript script hosts are not able to run a script if it is not stored in a file. But you can use mshta and the vbscript: protocol to run simple commands.
Anyway, for this case, it is easier to use
msg console "test"
edited to adapt to comments
i've being testing. vbscript parser in the mshta url has to face a lot of limitations. And problems with spaces, concatenation of commands with :, problems with procedure calling as a function but you can not use call keyword as a space is required, ....
The only stable, "easy" way of doing it is to prepare the vbscript to execute as a string, with no spaces inside it, and use the execute method to run it
mshta "vbscript:window.close(execute("msgbox"&chr(32)&"""test"":msgbox"&chr(32)&"""this"&chr(32)&"should"&chr(32)&"work"""))"
mshta "vbscript:window.close(execute("server=CreateObject(""WScript.Shell"").RegRead(""HKEY_CURRENT_USER\Volatile"&chr(32)&"Environment\LOGONSERVER""):For"&chr(32)&"i=1"&chr(32)&"to"&chr(32)&"3:msgbox"&chr(32)&"i"&chr(38)&"server:next"))"

Import External "Document" File in R Programming [closed]

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 8 years ago.
Improve this question
I am very new in R Programming, my concern is about importing "Document" kind of files. I say "Document" because when I go to "Get Info" and see what type of data it is, this is what I see:
I know how to open .txt or .csv files, but how about "document" types? Without resorting to exporting this kind of file manually using Excel.
I'm using Mac OS, btw.
Thanks!
You open the file, just like any other .txt file. Simply because it lacks a proper extension name, does not change much. (now if it is not a text file, that is another issue altogether, but I would bet it is)
Try the following:
read.table("~/SMSSpamCollection", header=TRUE, sep="\t")
Change "~/" to the "ptah/to/your/file/"
Mess around with header, sep, etc.
see ?read.table for more help

Ruby detect if a column value has changed [closed]

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 8 years ago.
Improve this question
So I have this line:
if self.company_changed?
And it works fine but this detects if the company has changed on the object. I need to know if the database value has changed and not if the value in memory has changed. So I tried this:
if :company_changed?
This seems to work in debug mode when I only execute the one line. If I let it run, it fails in testing on an infinite loop.
My question is what can be used in ruby to check to see if the column value has actually changed.
I'm pretty sure you're actually talking about ActiveRecord. In which case, you'd need to re-fetch the record to see if the value has changed in the database.
self.class.find(self.id).company != self.company
A general purpose method for this might be something like:
def attr_changed_in_db?(attr)
self.class.find(self.id).attributes[attr] != self.attributes[attr]
end
There is an excellent screencast on this by the great Ryan Bates.

Resources