Link to home
Start Free TrialLog in
Avatar of cvbmn
cvbmn

asked on

SetEnvironmentVariable PROBLEM

SetEnvironmentVariable PROBLEM

How to get in SHOWMESSAGE dialog box CHAR 'A' ?

---->>>Project1.DPR BEGIN---->>>
program Project1;

uses
  SysUtils, Dialogs, Math, Windows;

var I:integer;

begin
I:=FileCREATE('DATA.TXT');
FileWrite(I,'DATA.TXT',Length('DATA.TXT'));
FileSeek(I,1,1);
FileRead(I,PChar(SetEnvironmentVariable(PChar('DATA'),nil))^,1);
showmessage(GetEnvironmentVariable(PChar('DATA')));
end.
<<<----Project1.DPR END<<<----

PLEASE HELP.

THANK YOU.
Avatar of cvbmn
cvbmn

ASKER

Hi, to ALL !

I want to get 'A' from text 'DATA.TXT' in FILE 'DATA.TXT' !

In SHOWMESSAGE !

Thanks TO ALL.
Avatar of cvbmn

ASKER

But NOT using DELPHI native code as :
var c: char;

But something like :
SetEnvironmentVariable
Avatar of cvbmn

ASKER

I MEAN TO USE DELPHI NATIVE CODE !
But NOT SETTING VARIABLES like that :
var c: char;
IN
FileRead(I,c,1);
showmessage(c);

Instead using 'var c: char;' and 'c' in FileRead and ShowMessage.
To use something like that : SetEnvironmentVariable and GetEnvironmentVariable.
Avatar of ThievingSix
Not possible unless there is a read function and not procedure.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't understand why you don't want to declare c: Char variable and at same time you declare I: Integer... anyway one of methods:

procedure TForm1.Button8Click(Sender: TObject);
var fs: TMemoryStream;
      char_index: Integer;
begin
  char_index := 1;
  fs := TMemoryStream.Create;
  try
    fs.LoadFromFile('c:\lic.log');
    ShowMessage(PChar(Longint(fs.Memory) + char_index)^);
  finally
    fs.Free;
  end;
end;


ziolko.
if you want to use a text file to set environment variables

the text file should look like this
DATA=A
TESTME=Failure
TRYME=WhyNot

to upload this to the environment variables:

test it with
ShowMessage(GetEnvironmentVariable('TRYME'));




procedure Upload(aFileName: string);
var I: Integer;
  List: TStrings;
begin
  List := TStringList.Create;
  try
    List.LoadFromFile(aFileName);
    for I := 0 to List.Count - 1 do 
      if List[I] <> '' then 
        SetEnvironmentVariable(List.Names[I], List.ValueFromIndex[I]);
  finally
    FreeAndNil(List);
  end;  
end;

Open in new window

Avatar of cvbmn

ASKER

Thanks, to ALL !

But, how did You mean ThievingSix ?
"Not possible unless there is a read function and not procedure."

Is there some other read function to use it for read ?
Could You show me an example ?

Please HELP.
Thank YOU.
what are you actually trying to do ?
Avatar of cvbmn

ASKER

Here is what I made. But I want to put FileRead to, in FileWrite.

Please HELP.
Thank YOU.
program Project1;
 
uses
  SysUtils, Dialogs, Math, Windows;
 
begin
repeat
FileWrite(Trunc(((ORD(SetEnvironmentVariable(PChar('AHandle1'),PChar(inttostr((FileOpen('TEST.TXT',2))))))+ORD(SetEnvironmentVariable(PChar('AHandle2'),PChar(inttostr(strtoint('0'+GetEnvironmentVariable(PChar('AHandle2')))))))+ORD(SetEnvironmentVariable(PChar('AHandle3'),PChar(inttostr((FileCreate('TEST.TXT'))))))+
                ORD(SetEnvironmentVariable(PChar('AHandle2'),PChar(inttostr(strtoint(GetEnvironmentVariable(PChar('AHandle1')))+strtoint(GetEnvironmentVariable(PChar('AHandle2')))-1+strtoint(GetEnvironmentVariable(PChar('AHandle3')))+2+abs(trunc(((strtofloat(GetEnvironmentVariable(PChar('AHandle2')))))/((strtofloat(GetEnvironmentVariable(PChar('AHandle2')))-1)))) ))))+
                FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2))/(FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2)+10000000)))+
                strtoint(GetEnvironmentVariable(PChar('AHandle2')))+
                Trunc(Ord(SetEnvironmentVariable(PChar('Buffer'),PChar(STRING(chr(Trunc(((FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) - (Trunc((FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) / ({sasalinelength}1 * Power({sasabase}256,
                Trunc(((FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) + {sasalinelength}1) / {sasalinelength}1) * {sasalinelength}1 -
                (FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1)))) * ({sasalinelength}1 * Power({sasabase}256, Trunc(((FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) + {sasalinelength}1) / {sasalinelength}1) * {sasalinelength}1 -
                (FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1))))) / ({sasalinelength}1 * Power({sasabase}256, Trunc(((FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) + {sasalinelength}1) / {sasalinelength}1) * {sasalinelength}1 - (FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2) - 1) - 1))) + 34)) )))/1000000),PChar(GetEnvironmentVariable(PChar('Buffer')))^,Length(GetEnvironmentVariable(PChar('Buffer'))));
until FileSeek(strtoint(GetEnvironmentVariable(PChar('AHandle2'))),0,2)>256-34
end.

Open in new window

well, the first thing that comes to mind when i see this:
make some code, that is impossible to understand and impossible to maintain.

your solution comes very close

my question:
why would you want to write it like that ?
I don't think you will find a lot of people interested in something like this


My eyes...
Avatar of cvbmn

ASKER

Thanks, Geert_Gruwez !

Well, I decided to learn how fast I can write code for DELPHI !
To show somebody what DELPHI can do !

Maybe I'll decide to sell projects like DELPHI !
I'll be proud to be part of DELPHI users/members !

To have customers like DELPHI users/members !

Isn't DELPHI great project !
It is my dream to share my knowledge with others !
Maybe tomorrow my dream come trhuth !

Maybe tomorrow I decide !

Please HELP.
Thank YOU.
I have no problem with helping anybody.
I just refuse to read something more than 10 times to understand what it does.

Avatar of cvbmn

ASKER

Thanks, Geert_Gruwez !
But, I am not so good in English, and even in programming.
So, when I finish that project. It should be an easy project anyway.
I'll show You everething what I did.
But not now, when I don't know basics of Windows, Delphi etc.
I'll ask question, and I'll attach project code as I did in comment of that question.
Complete finished source code of my project.
Why is such a problem to give solution for that problem.
Put FileRead to FileWrite Handle section.
With conditions as I described.

Please HELP.
Thank YOU.
Avatar of cvbmn

ASKER

Thanks, To All !

But, please tell me if there is possible to solve solution
for that problem.

If it is not. But tell me. It is OK too.

But tell me PLEASE.

Please HELP.
Thank YOU to ALL.