Using TIdHTTPServer thread safe in D2005












0















This question has been asked very often and I've spent hours reading, trying, testing with no result.



I guess it has to do with my older 2005 version.



Below is the code I tried after reading a post in the Embarcadero forum answered by Remy Lebeau:



Thread: How to handle multiple HTTP sessions with Indy10 TIdHTTPServer



procedure TMainForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Msg : String;
begin
if ARequestInfo.QueryParams <> '' then
begin
Msg := DateTimeToStr(Now) + ': ReqParam "' + ARequestInfo.QueryParams + '"';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
AResponseInfo.ContentText := '<HTML><BODY>Query Params found.</BODY></HTML>';
end
else
begin
AResponseInfo.ContentText := '<HTML><BODY>Error: No Query Params.</BODY></HTML>';
Msg := DateTimeToStr(Now) + ': Error: No Query Params';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
end;
end;


What I'm aiming for is accessing a memo or log file entry in a thread safe manner. Somehow using TThread.Synchronize() or TThread.Queue() doesn’t compile.



When adding the TThread.Queue() line as suggested by Remy, the error I get is:




E2029 Expression expected but procedure found




Does somebody have an alternative that I can use in Delphi 2005?



Edit: this is what I see from code completion:



The design view for TThread










share|improve this question




















  • 2





    Please add the code snip from the pic into the question...

    – Moshe Slavin
    Dec 31 '18 at 10:38











  • Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

    – Virginia
    Dec 31 '18 at 11:29













  • The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

    – Remy Lebeau
    Jan 1 at 17:26











  • That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

    – D2005_MdK
    Jan 1 at 17:48











  • @D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

    – Remy Lebeau
    Jan 6 at 6:25
















0















This question has been asked very often and I've spent hours reading, trying, testing with no result.



I guess it has to do with my older 2005 version.



Below is the code I tried after reading a post in the Embarcadero forum answered by Remy Lebeau:



Thread: How to handle multiple HTTP sessions with Indy10 TIdHTTPServer



procedure TMainForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Msg : String;
begin
if ARequestInfo.QueryParams <> '' then
begin
Msg := DateTimeToStr(Now) + ': ReqParam "' + ARequestInfo.QueryParams + '"';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
AResponseInfo.ContentText := '<HTML><BODY>Query Params found.</BODY></HTML>';
end
else
begin
AResponseInfo.ContentText := '<HTML><BODY>Error: No Query Params.</BODY></HTML>';
Msg := DateTimeToStr(Now) + ': Error: No Query Params';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
end;
end;


What I'm aiming for is accessing a memo or log file entry in a thread safe manner. Somehow using TThread.Synchronize() or TThread.Queue() doesn’t compile.



When adding the TThread.Queue() line as suggested by Remy, the error I get is:




E2029 Expression expected but procedure found




Does somebody have an alternative that I can use in Delphi 2005?



Edit: this is what I see from code completion:



The design view for TThread










share|improve this question




















  • 2





    Please add the code snip from the pic into the question...

    – Moshe Slavin
    Dec 31 '18 at 10:38











  • Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

    – Virginia
    Dec 31 '18 at 11:29













  • The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

    – Remy Lebeau
    Jan 1 at 17:26











  • That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

    – D2005_MdK
    Jan 1 at 17:48











  • @D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

    – Remy Lebeau
    Jan 6 at 6:25














0












0








0








This question has been asked very often and I've spent hours reading, trying, testing with no result.



I guess it has to do with my older 2005 version.



Below is the code I tried after reading a post in the Embarcadero forum answered by Remy Lebeau:



Thread: How to handle multiple HTTP sessions with Indy10 TIdHTTPServer



procedure TMainForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Msg : String;
begin
if ARequestInfo.QueryParams <> '' then
begin
Msg := DateTimeToStr(Now) + ': ReqParam "' + ARequestInfo.QueryParams + '"';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
AResponseInfo.ContentText := '<HTML><BODY>Query Params found.</BODY></HTML>';
end
else
begin
AResponseInfo.ContentText := '<HTML><BODY>Error: No Query Params.</BODY></HTML>';
Msg := DateTimeToStr(Now) + ': Error: No Query Params';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
end;
end;


What I'm aiming for is accessing a memo or log file entry in a thread safe manner. Somehow using TThread.Synchronize() or TThread.Queue() doesn’t compile.



When adding the TThread.Queue() line as suggested by Remy, the error I get is:




E2029 Expression expected but procedure found




Does somebody have an alternative that I can use in Delphi 2005?



Edit: this is what I see from code completion:



The design view for TThread










share|improve this question
















This question has been asked very often and I've spent hours reading, trying, testing with no result.



I guess it has to do with my older 2005 version.



Below is the code I tried after reading a post in the Embarcadero forum answered by Remy Lebeau:



Thread: How to handle multiple HTTP sessions with Indy10 TIdHTTPServer



procedure TMainForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Msg : String;
begin
if ARequestInfo.QueryParams <> '' then
begin
Msg := DateTimeToStr(Now) + ': ReqParam "' + ARequestInfo.QueryParams + '"';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
AResponseInfo.ContentText := '<HTML><BODY>Query Params found.</BODY></HTML>';
end
else
begin
AResponseInfo.ContentText := '<HTML><BODY>Error: No Query Params.</BODY></HTML>';
Msg := DateTimeToStr(Now) + ': Error: No Query Params';
TThread.Queue(nil,
procedure
begin
Memo1.Lines.Add(Msg);
end
);
end;
end;


What I'm aiming for is accessing a memo or log file entry in a thread safe manner. Somehow using TThread.Synchronize() or TThread.Queue() doesn’t compile.



When adding the TThread.Queue() line as suggested by Remy, the error I get is:




E2029 Expression expected but procedure found




Does somebody have an alternative that I can use in Delphi 2005?



Edit: this is what I see from code completion:



The design view for TThread







indy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 6 at 6:19









Remy Lebeau

339k19263458




339k19263458










asked Dec 31 '18 at 10:30









D2005_MdKD2005_MdK

12




12








  • 2





    Please add the code snip from the pic into the question...

    – Moshe Slavin
    Dec 31 '18 at 10:38











  • Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

    – Virginia
    Dec 31 '18 at 11:29













  • The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

    – Remy Lebeau
    Jan 1 at 17:26











  • That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

    – D2005_MdK
    Jan 1 at 17:48











  • @D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

    – Remy Lebeau
    Jan 6 at 6:25














  • 2





    Please add the code snip from the pic into the question...

    – Moshe Slavin
    Dec 31 '18 at 10:38











  • Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

    – Virginia
    Dec 31 '18 at 11:29













  • The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

    – Remy Lebeau
    Jan 1 at 17:26











  • That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

    – D2005_MdK
    Jan 1 at 17:48











  • @D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

    – Remy Lebeau
    Jan 6 at 6:25








2




2





Please add the code snip from the pic into the question...

– Moshe Slavin
Dec 31 '18 at 10:38





Please add the code snip from the pic into the question...

– Moshe Slavin
Dec 31 '18 at 10:38













Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

– Virginia
Dec 31 '18 at 11:29







Welcome to Stack Overflow. Please show us your code as actual text, a code snippet. If the link of your image disappears, nobody will know what your question was. By Asking a good question you help us to understand you and your question/problem better, which in turn might give you a better and more specific response. Please also read Why not upload images of code on SO when asking a question?

– Virginia
Dec 31 '18 at 11:29















The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

– Remy Lebeau
Jan 1 at 17:26





The static versions of TThread.Synchronize() and TThread.Queue() have existed since D7 and D8, respectively, so they definitely exist in D2005. But, if you are having trouble using them, an alternative is Indy's TIdSync and TIdNotify classes, respectively.

– Remy Lebeau
Jan 1 at 17:26













That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

– D2005_MdK
Jan 1 at 17:48





That puzzles me, as I don't see the TThread.Synchronize at all... I've added a screenshot...

– D2005_MdK
Jan 1 at 17:48













@D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

– Remy Lebeau
Jan 6 at 6:25





@D2005_MdK then use TThread.StaticSynchronize() or TThread.StaticQueue(), both of which are clearly visible in your screenshot.

– Remy Lebeau
Jan 6 at 6:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986380%2fusing-tidhttpserver-thread-safe-in-d2005%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986380%2fusing-tidhttpserver-thread-safe-in-d2005%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter