Giter Club home page Giter Club logo

Comments (28)

silvioprog avatar silvioprog commented on July 19, 2024

Can you send the full code? It's almost impossible to reproduce a complex problem without having the full code.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

só tem a função CHome alem doque esta ai

only has the function CHome doque beyond this there

function THome.CHome: TJTemplate;
begin
Result.HTMLSupports := False;
Result.LoadFromFile(ANIVEL_ACIMA+AROOT_DIR_HTML+'home.html');
Result.Replace;
end;

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

I couldn't test this code, I don't know what could be wrong. Without the full code to test it, unfortunately no one can help you.

Again, isolate the problem in a small project, compress it with ZIP, upload to a site of file sharing and paste the link here.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

ready, oh this example.

http://www.sendspace.com/file/wyfr8a

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

I tested it. Isn't a bug. It's a fail in your implementation.

Change your implementation for it:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction, JTemplate, RUtils;

type
  TMyAction = class(TBrookAction)
  public
    procedure Get; override;
  end;

implementation

procedure TMyAction.Get;
var
  jtem: TJTemplate;
begin
  jtem := TJTemplate.Create;
  jtem.HTMLSupports := False;
  jtem.LoadFromFile('../pg1.html');
  jtem.Fields.Add('centro', FileToStr('../centro.html'));
  jtem.Replace;
  try
    Write(jtem.Content);
  finally
    jtem.Free;
  end;
end;

initialization
  TMyAction.Register('*');

end.

The result will:

titulo 1

Primeiro paragrafo

centro da pagina de teste, problema com content

rodapé da pagina

Download RUtils from: https://github.com/silvioprog/rutils.

Good luck, and close this issue if it work fine for you please!

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

eu não posso utilizar o filetostr, porque nesse outro html pode conter outros itens no qual eu precize utilizar o jtamplate para sobrescrever com o "tamplat.fields.add('var', 'valor');", então continua sendo um bug.

I can not use the filetostr because that other html can contain other items in which I precize jtamplate use to overwrite the "tamplat.fields.add ('var', 'value');" then still a bug.

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Isn't bug! You is using an instance of JTemplate twice, so, the LoadFromFile reads the file twice, replacing the previously loaded file before. The logic in your code is wrong.

Or you keep the previously loaded file in a variable to use LoadFromFile twice, or your code will never work.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

acho que você esta errado, e não esta dando atenção para o propósito da utilização que mais de uma instancia do Jtamplate daria para o desenvolvedor, eu ja uso isso, mas em forma de gambiarra, tenho mais de 10 Jtemplate a mesmo tempo, não são uma mas sim mais dez instancias, mas pra que funcione eu tenho que criar variaveis e ir jogando os conteudos dentro de variaveis, sei que você é inteligente pra entender o funcionamento e não me pedir um outro exemplo disso, caso não queira dar atenção para o bug, isso fica a seu critério, mas continua sendo um bug.

I think you're wrong, and is not paying attention to the purpose of using more than one instance of Jtamplate give to the developer, I already use it, but in the form of workaround, I have over 10 Jtemplate the same time, are not one but ten instances, but for it to work I have to create variables and go throwing the contents into variables, I know you are smart to understand the operation and did not order another example, if you do not want to give attention to the bug, it is up to you, but still a bug.

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

I can't fix out what is explicitly clear that isn't bug.

You are using LoadFromFile twice, so the old content is overwritten. What class you use in Free Pascal that allows use in this way?

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

e eu não estou usando a instancia do jtemplate duas vezes, são instancias diferentes...

and I'm not using an instance of jtemplate twice, instances are different ...

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

... See your implementation again, I commented it:

procedure TMyAction.Get;
Var
  jtem:TJTemplate;
begin
  jtem:=TJTemplate.Create;
  jtem.HTMLSupports := False;
  jtem.LoadFromFile('../pg1.html'); << FIRST load ...
  jtem.Fields.Add('centro', CHome.Content <<< LAST load, using the same instance, that is jtem );
  jtem.Replace;
  try
    write(jtem.Content);
  finally
    jtem.Free;
  end;
end;

It's wrong.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

vou tentar novamente, mesmo achando desnecessario e ja vi que não vai resolver nada, vou ter que continuar com as gambiarras, são instancias diferentes, eu não dou um loadfromfile duas vezes no mesmo jtem.loadformfile, são em instancias separadas, mas fico por aqui, creio que fiz minha contribuição, encontrei o bug e reportei para o criador, agora cabe a você dar o proximo passo. eu não sou tão brilhante assim.

I'll try again, even finding unnecessary and've seen that will not solve anything, I have to continue with the hacks are different instances, I do not give a LoadFromFile twice in the same jtem.loadformfile are in separate instances, but I'm here I believe I made my contribution, I found the bug and reported it to the creator, now it's up to you to take the next step. I'm not so bright.

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

See in my comment above. Your logic is wrong.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

por este motivo eu acho desnecessario um projeto demo, na primeira mensagem tem parte do codigo onde o CHOME.CONTENT, não esta atrelado a nada, esta vagando pelo corpo do get, e mesmo assim ele sobrepões tudo....

for this reason I think unnecessary project demo, the first message is part of the code where the CHOME.CONTENT, is not tied to anything, this wandering the body get, and even then it overlaps everything ....

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

I'll make other example and show them. Wait please...

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

não precisa se dar ao trabalho. O problema é com o content, em diversas situações muitos programadores vão precisar trabalhar com array de paginas, como é feito em outras linguagens, mas ja percebi que vamos ter que usar de artificios e gambiarras pra que isso funcione com a brook, esperava eu que postando aqui direto no site do projeto talves pudessemos resolver.

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

I'll reply in Portuguese, my English is not very good.

Você está sendo muito dramático. Tenha calma, vou mostrar o problema em SEU código, é impossível que o depurador do Free Pascal esteja errado.

Vou mandar um código para você depurar e ver com seus próprios olhos. Só um momento por favor...

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

não é ser dramático, é algo simples, um content de uma outra instancia esta sobrepondo o outro, e isso não esta certo, você só não quer entender, se eu tiver que usar 3 jtemplate e dar um loadfromfile, então eu não posso? então ele não esta se comportando como um objeto, ou então a brook esta pegando qualquer qualquer content e jogando na saida....

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Pronto. Baixe esse projeto: http://www.sendspace.com/file/lega5k.

Notará que o botão "Run" do Lazarus estará habilitado, e notará também que deixei dois breakpoints. Fiz isso para você depurar aí. Para testar é muito simples, abra o projeto na IDE, use F9 para rodar o programa e logo em seguida chame a seguinte URL em seu browser:

http://localhost:5445

O ícone da IDE piscará na barra de tarefas. Vá até ela e use pausadamente F8, para ir executando o código linha a linha. Não deixe de ver os comentários no código, lá explico tudo claramente.

Se tiver dúvidas ou souber outra forma de expor o problema, mande em outro demo, detalhando-o. Caso entenda que é problema de logica, feche este issue por favor.

PS. o debug do Lazarus não está OK no Linux, já reportei mas não sei se já resolveram, logo, é altamente recomendado você fazer este teste no Windows.

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Pera que vou mandar outro código, meu comentário ficou errado no primeiro ...

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Pronto: http://www.sendspace.com/file/jbply3.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

olha o exemplo....agora o conteudo esta sendo atribuido a uma variavel, eu vou ficando por aqui, e vou deixar a issue aberta, pra ver se alguem concegue resolver

http://www.sendspace.com/file/t72eyb

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Você escreveu:

conteudo_do_chome := CHome.Content;   //agora esta sendo atribuido a algo?

A resposta é a mesma: Não! Pois CHome continua sem ser atribuída a nada, e continua usando uma instância fantasma de jtem. O que você está fazendo aí é apenas passando um valor para conteudo_do_chome porém de uma instância fantasma em CHome. Repetindo, continua sem atribuir CHome a nada. Entendeu?

Ou você atribui CHome a outra instância que não seja jtem, ou seu código nunca irá funcionar corretamente. Eu pensei que depurando o código você ia ver e entender, mas acho que não depurou.

Vou fechar este issue. Está super claro para qualquer um que seu CHome é um método implementado na ação e que não está apontado para ninguém, e você quer pq quer que este método seja "magicamente" atribuído a alguma instância. Não sei nem como isso não deu um AV, mas uma hora que o processador decidir liberar o lixo temporário criado pela primeira instancia você verá o que estou tentando explicar repetidamente e acredito que entenderá.

Isso funcionaria:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction, JTemplate;

type
  TMyAction = class(TBrookAction)
  private
    function CHome: TJTemplate;
  public
    procedure Get; override;
  end;

implementation

function TMyAction.CHome: TJTemplate;
begin
  Result := TJTemplate.Create;
  Result.HTMLSupports := False;
  Result.LoadFromFile('centro.html');
  Result.Replace;
end;

procedure TMyAction.Get;
var
  jtem: TJTemplate;
begin
  jtem := TJTemplate.Create;
  try
    jtem.HTMLSupports := False;
    jtem.LoadFromFile('pg1.html');
    jtem.Fields.Add('centro', CHome.Content);
    jtem.Replace;
    Write(jtem.Content);
  finally
    CHome.Free;
    jtem.Free;
  end;
end;

initialization
  TMyAction.Register('*');

end.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

desde o inicio vc sabia da resposta? porque demorou tanto?, obrigado! resolveu minhas gambiarras, agora vou testar...

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Não meu amigo, não sabia, pois não sou adivinho. E depois deste seu último comentário fico sem entender se isso seja realmente um pedido de ajuda ou uma provocação.

Que bom que resolveu o problema, e que tenha entendido que o erro era em sua lógica, mesmo eu tendo deixado isso bem claro no início e você oferecido resistência em entender.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

não meu amigo, não é provocação, na verdade ajuda eu te pedi pelo gtalk...

from brookframework.

silvioprog avatar silvioprog commented on July 19, 2024

Então tudo certo.

from brookframework.

andersonsc10 avatar andersonsc10 commented on July 19, 2024

tudo 100% certo, obrigado novamente...

from brookframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.